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

"Cannot find module" due to compileOptions.paths + ts-node/register #52

Open
JakobJingleheimer opened this issue Jul 8, 2018 · 4 comments

Comments

@JakobJingleheimer
Copy link
Contributor

JakobJingleheimer commented Jul 8, 2018

Versions:

  • mocha: ^5.2.0
  • ts-node: ^7.0.0
  • tsconfig-paths ^3.4.2
  • typescript: ^2.9.2

Error:

src/someFile.ts(1,24): error TS2307: Cannot find module '@lodash/camelCase'.

someFile.ts:

import _camelCase from '@lodash/camelCase';

// …
tsconfig.csj.json
{
  "compilerOptions": {
    "module": "commonjs",
    "outDir": "./lib/cjs",
    "paths": {
      "@lodash/*": [
        "node_modules/lodash/*",
        "node_modules/@types/lodash/*"
      ]
    }
  },
  "extends": "./tsconfig.json"
}

Commands:

"build:cjs": "tsc --project tsconfig.cjs.json",
// …
"test": "mocha -r ts-node/register -r tsconfig-paths/register -P tsconfig.cjs.json ./src/**/*.spec.ts"

The build using that same tsconfig file runs just fine. If I remove the @, the test command runs fine.

P.S. Sorry, I'm not sure whose issue this is (tsconfig-paths, ts-node).

Why I'm using the seemingly unnecessary `@lodash` at all

I'm using paths in generating different builds: cjs uses lodash, and es uses lodash-es, so I'm using the two different tsconfigs extending a main one for that.

@beejeon
Copy link

beejeon commented Jul 12, 2018

@jshado1
What is @lodash/camelCase ?
If it's your package (not npm published), Can you see if this is solved by #53

@JakobJingleheimer
Copy link
Contributor Author

@todtod80 @lodash/camelCase is lodash/camelCase (which is definitely publish in npm) where @lodash is an alias defined in paths (see tsconfig.csj.json in my original post).

@jonaskello
Copy link
Member

@jshado1 Would it be possible for you to setup a small reproduction of this issue in a separate github repo so I can take a closer look?

@JakobJingleheimer
Copy link
Contributor Author

JakobJingleheimer commented Jul 14, 2018

@jonaskello, is this small enough https://github.com/jshado1/ssr-storage ?

The file containing the @lodashs is src/cookie.ts, and the command to run the tests is npm run test (alias in package.json).

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