Angular 7:通过npm链接添加本地模块

时间:2019-10-07 09:06:26

标签: node.js angular typescript npm

我创建了一个包,其中文件夹之外的模块带有应用程序,其中应包含要测试的模块。然后,我用npm link @scope/module-name添加了软件包。之后,我将路径添加到根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": {
      "@scope/module-name": [
        "node_modules/@scope/module-name"
      ],
      "@scope/module-name/*": [
        "node_modules/@scope/module-name/*"
      ]
    }
  }
}

我还在include的{​​{1}}中添加了包裹

tsconfig.app.json

是的,我在{ "extends": "../tsconfig.json", "compilerOptions": { "outDir": "../out-tsc/app", "types": [] }, "include": [ "**/*.ts", "../node_modules/@scope/**/*.ts", ], "exclude": [ "test.ts", "**/*.spec.ts" ] } 中添加了"preserveSymlinks": true,就像在SO的类似问题中所说的那样。

angular.json中,我正在做

app.module.ts

但我仍然出错了

  ./node_modules/@scope/module-name/public_api.d.ts模块中的

ERROR   构建失败(来自./node_modules/@ngtools/webpack/src/index.js):   错误:   D:\ internal \ test-app \ node_modules @ scope \ module-name \ public_api.d.ts   在TypeScript编译中丢失。请确保它在   您的tsconfig通过“文件”或“包含”属性。

如何解决该错误?

0 个答案:

没有答案