Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lerna yarn workspaces and typescript project reference #65

Closed
jaimesangcap opened this issue Nov 21, 2018 · 4 comments
Closed

lerna yarn workspaces and typescript project reference #65

jaimesangcap opened this issue Nov 21, 2018 · 4 comments

Comments

@jaimesangcap
Copy link

jaimesangcap commented Nov 21, 2018

I have this sample repo branch tsconfig-paths-issue https://github.com/jaimesangcap/lerna-ts-monorepo/tree/tsconfig-paths-issue
using lerna, yarn workspaces and typescript project references but it does not seem to work.

It cannot resolve the relative path of the module with error:

module.js:545
    throw err;
    ^

Error: Cannot find module '@elts/common/testing/seed'
    at Function.Module._resolveFilename (module.js:543:15)
    at Function.Module._resolveFilename (/Users/jaime/sanay/lerna-ts-monorepo/node_modules/tsconfig-paths/lib/register.js:75:40)
    at Function.Module._load (module.js:470:25)
    at Module.require (module.js:593:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/Users/jaime/sanay/lerna-ts-monorepo/packages/api/lib/index.js:3:14)
    at Module._compile (module.js:649:30)
    at Object.Module._extensions..js (module.js:660:10)
    at Module.load (module.js:561:32)
    at tryModuleLoad (module.js:501:12)

to reproduce:

npx lerna bootstrap at project root
tsc -b
TS_NODE_PROJECT=tsconfig.settings.json node -r tsconfig-paths/register packages/api/lib/index.js

then error above should show

@jonaskello
Copy link
Member

You may want to take a look at this example.

@jaimesangcap
Copy link
Author

jaimesangcap commented Nov 22, 2018

@jonaskello Actually that's the one I'm following along 😄
I've got it working in this branch tsconfig-paths-solved https://github.com/jaimesangcap/lerna-ts-monorepo/tree/tsconfig-paths-solved

the only difference is that in the tsconfig.json, I'm pointing the path to the transpiled path and not the source.

NOT working:
tsconfig.json

"paths": {
      "@elts/common/*": ["./common/src/*"]
    }

WORKING:

"paths": {
      "@elts/common/*": ["./common/lib/*"]
    }

Do you have idea why is that?

@flash1293
Copy link

You are mixing js and ts execution contexts here.

If you are executing node -r tsconfig-paths/register packages/api/lib/index.js, you are using solely the js files - the only thing typescript-related are the path-resolutions, but node is always looking for js files. Since there are no js files in common/src, only ts files, node doesn't know what to do.

If you are executing ts-node -r tsconfig-paths/register, you can use either js files or ts files, ts-node knows how to deal with both of them (ts-node -r tsconfig-paths/register packages/api/lib/index.js or ts-node -r tsconfig-paths/register packages/api/src/index.ts).

If you don't need the compiled js files and using ts-node is fine for you, just skip the compilation step completely and map everything to the src folders -

"paths": {
      "@elts/common/*": ["./common/src/*"]
    }

and
ts-node -r tsconfig-paths/register packages/api/src/index.ts

@jaimesangcap
Copy link
Author

That makes sense, thank you for explaining. For now I guess I will just use ts-node

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants