tsconfig-paths icon indicating copy to clipboard operation
tsconfig-paths copied to clipboard

Module not found: tsconfig compileOptions.paths are not being resolved

Open r0skar opened this issue 6 years ago • 1 comments

I am not sure whether this is the right place to report this issue:

I am using webpack with ts-node in order to be able to use typescript as a configuration language. I have created a custom tsconfig file for webpack:

// tsconfig.webpack.json
{
  "compilerOptions": {
    "module": "commonjs",
    "target": "es5",
    "esModuleInterop": true,
    "baseUrl": "./",
    "paths": {
      "CONFIG": ["config/config.ts"]
    }
  }
}

Everything works fine, except the path aliases are not being resolved when running webpack:

cross-env TS_NODE_PROJECT='tsconfig.webpack.json' webpack --config app/config/webpack/webpack.prod.ts
// Works fine.
import { DIST_ROOT } from '../../../config/config'

// Error: Cannot find module 'CONFIG'
import { DIST_ROOT } from 'CONFIG'

r0skar avatar Apr 06 '19 10:04 r0skar

I believe you need ./config/config.ts and not config/config.ts as it would resolve to an npm module without the ./ in the front.

azarus avatar Apr 08 '19 11:04 azarus