My current project involves the use of multiple tsconfig.json
files. I'm aiming to streamline all imports, but oddly enough, shortened imports aren't functioning correctly in a specific situation.
Here's how my project is structured:
foo/
| main.ts
| tsconfig.json
projects/
| bar/
| index.ts
tsconfig.json
Every time I try to compile foo/main.ts
, I encounter this error: Cannot find module @bar/shared
.
Here are some key points:
The file projects/bar/index.ts
merely exports a basic class: export class Foo {}
Within foo/main.ts
, I attempt to import the Foo
class like so:
import {Foo} from '@bar/shared';
Lastly, the tsconfig.json
located within the foo
directory:
{
"extends": "../tsconfig.json",
"compilerOptions": {
"target": "es2015",
"module": "commonjs",
"moduleResolution": "node",
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"resolveJsonModule": true,
"lib": ["es6", "dom"],
"types": [
"node"
],
"outDir": "../dist/foo"
}
}
And the main root tsconfig.json
:
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./",
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"module": "es2015",
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"importHelpers": true,
"target": "es5",
"typeRoots": [
"node_modules/@types"
],
"lib": [
"es2018",
"dom"
],
"paths": {
"@bar/shared": ["projects/bar"]
}
}
}
My IDE shows no issues, but unfortunately, I am unable to successfully compile.