首页 > 解决方案 > 打字稿编译问题使用“参考”来获取项目中的共享文件

问题描述

我正在尝试编译我的 Typescript 项目,该项目使用项目范围之外的一些共享文件。我试图在输出目录中有一个扁平的结构。它看起来像这样:

命令 'tsc --build' 没有错误(/shared/interface 中的部分也已正确编译),但项目输出目录不包含 test.interface.js 文件和 test.model 中的导入路径。 ts 到达 test.interface 也没有改变。所以当我运行项目时,我显然有一个错误。共享文件夹中的 tsconfig.json 如下所示:

    {
  "compilerOptions": {
    "module": "commonjs",
    "declaration": true, 
    "declarationMap": true,
    "target": "es6",
    "rootDir": ".",   
    "composite": true,     
  }
}

项目 tsconfig.json 看起来像这样:

    {
  "compilerOptions": {
    "module": "commonjs",
    "esModuleInterop": true,
    "target": "es6",
    "moduleResolution": "node",
    "sourceMap": true,
    "rootDir":"src",
    "outDir": "dist"
  },
  "lib": ["es2015"],
  "references": [
      { "path": "../../shared/interface/" }
  ]
}

我不知道我做错了什么。谢谢你的帮助。

标签: typescriptcompilationreference

解决方案


推荐阅读