#help with ts yarn monorepo setup

39 messages · Page 1 of 1 (latest)

outer cloak
#

I have a typescript yarn monorepo that has 2 apps:

  • a nextjs v15 app
  • nodejs app (discord bot)

I want to import a shared package @repo/core and others in both of these apps but I am not able to setup it up. I tried to tweak the tsconfig a lot but keep getting MODULE_NOT_FOUND when trying 'yarn dev' in the bot app.
When trying to build also it is not able to find the local packages in the workspace.

I will be really glad if someone can help me. I have attached the project source code too.
Also when importing should we be importing from the root folder like:
@repo/core/commands/about
or from the src folder like:
@repo/core/src/commands/about

rough apex
#

!:paths%

coarse sandalBOT
#
tjjfvi#0
`!t6:paths-are-not-magic`:

The paths and baseUrl compiler options don't cause any remapping of imports paths, they only inform TS of existing mappings, which you'll have to setup with some other tool.

baseUrl is a pretty well-supported option (e.g. using the NODE_PATH environment variable with node or resolve.modules with webpack).
paths can be trickier to setup, (especially with node see this for node), and you may find it to not be worth the effort.

rough apex
#

please don't submit your code as a zip file. or any files for that matter

outer cloak
#

ok will remove it

#

will a github repo be better?

rough apex
#

sure

#

but really the only parts needed are package.json/tsconfig.json

outer cloak
rough apex
#

you don't have anything specifying @repo there

#

neither runtime nor to ts

outer cloak
#

@repo is mentioned in the name field in package.json of the packages in /packages/*

rough apex
#

ah, i see. is it being installed correctly though?

#

@repo/core doesn't exist on npm, at least not publically

#

don't you need a file specifier there

outer cloak
#

its a local package, in packages/core

rough apex
#

you aren't specifying that in your apps' package.jsons

outer cloak
#

its specified as a dependency in apps/bot/package.json

rough apex
#

it's specified as an npm dependency there

outer cloak
#

im using yarn and the yarn install works and it installs the packages

rough apex
#

thonk you sure? have you checked the node_modules?

outer cloak
rough apex
#

haven't used yarn, but according to docs you'd need workspace:*, so kinda surprised there..

#

what error are you getting exactly?

outer cloak
#

its not able to find the @repo/core/commands

#

in trying to build the apps/bot

rough apex
#

i thought you were getting a runtime error?

outer cloak
#

runtime error is when i try to run it directly using tsx rather than building it using tsc

rough apex
agile voidBOT
#
"main": "index.js",
outer cloak
#

this is the runtime error

rough apex
rough apex
#

core doesn't specifically export those with subpaths

outer cloak
#

how do i set that up

rough apex
outer cloak
#

or should i import from @repo/core/src/commands/about

rough apex
#

probably shouldn't, no