Try to search your question here, if you can't find : Ask Any Question Now ?

TypeScript project with references

HomeCategory: stackoverflowTypeScript project with references
bhawya asked 2 weeks ago

I use project references to reference “shared” project from “front” and “back” ones.

Project structure:

./back
./back/tsconfig.json
./shared/src/
./shared/
./shared/tsconfig.json
./shared/src/
./front
./front/tsconfig.json
./front/src

I am tring to import a module from the shared project:

import Article from "@shared/src/article";            // alias path
import Article from "../../../../shared/src/article"; // full relative path
export default class ArticleViewModel {
}

The following errors are shown:

For alias path:

Cannot find module ‘@shared/src/article’. ts(2307)

For full relative path:

Output file ‘../../../../shared/src/article’ has not been built from source file ‘c:/{SOMEWHERE_IN_MY_PC}/shared/src/article.ts’. ts(6305)

Intellisense (VS Code) does work for both alias and relative options:

Intellisense

./front/tsconfig.json contents:

{
    "compilerOptions": {
        "allowSyntheticDefaultImports": true,
        "baseUrl": ".",
        "module": "amd",
        "noEmitOnError": true,
        "noImplicitAny": false,
        "out": "./lib/front-bundle.js",
        "paths": {"@shared/*" : ["../shared/*"]},
        "preserveConstEnums": true,
        "removeComments": true,
        "sourceMap": true,
        "target": "es2015",
        "watch": true
    },
    "include": [
        "./src/**/*.ts",
    ],
    "references": [
        {
            "path": "../shared"
        }
    ]
}

./shared/tsconfig.json contents:

{
    "compilerOptions": {
        "allowSyntheticDefaultImports": true,
        "composite": true,
        "declaration": true,
        "module": "amd",
        "noEmitOnError": true,
        "noImplicitAny": false,
        "out": "./lib/shared-bundle.js",
        "preserveConstEnums": true,
        "removeComments": true,
        "sourceMap": true,
        "target": "es2015",
        "watch": true
    },
    "include": [
        "./src/**/*.ts",
    ]
}
1 Answers
Best Answer
Mikhail answered 2 weeks ago
Your Answer

0 + 17 =

Popular Tags

WP Facebook Auto Publish Powered By : XYZScripts.com