缺少 *.ts 文件(由于 `npm link` ?) [英] Missing *.ts files (due to `npm link` ?)
问题描述
我在 Angular5 项目中有这个导入语句:
I have this import statement in an Angular5 project:
import {plugins, SCECodeGenType} from 'sce-plugins/code-generation';
这将解析为我文件系统上的此路径:
this resolves to this path on my filesystem:
/Users/.../suman-chrome-extension/node_modules/sce-plugins/code-generation/index.d.ts
使用 ng build -w
构建应用程序时,我收到此错误:
When building the app with ng build -w
, I get this error:
ERROR in ../sce-plugins/code-generation/index.ts Module build failed: Error: /Users/alexamil/WebstormProjects/oresoftware/sumanjs/sce-plugins/code-generation/index.ts is missing from the TypeScript compilation. Please make sure it is in your tsconfig via the 'files' or 'include' property.
at AngularCompilerPlugin.getCompiledFile (/Users/alexamil/WebstormProjects/oresoftware/sumanjs/suman-chrome-extension/node_modules/@ngtools/webpack/src/angular_compiler_plugin.js:662:23)
at plugin.done.then (/Users/alexamil/WebstormProjects/oresoftware/sumanjs/suman-chrome-extension/node_modules/@ngtools/webpack/src/loader.js:467:39)
at <anonymous> @ ./src/app/shared/services/lang.service.ts 14:24-62 @ ./src/app/app.module.ts @ ./src/main.ts @ multi ./src/main.ts
我相信这是因为我使用 npm link
来链接 'sce-plugins'
项目以进行本地开发.
I believe it's because I am using npm link
to link the 'sce-plugins'
project for local development.
我在这里看到在 Angular5 项目中使用 npm link
的一些问题:
I see some issues with using npm link
with Angular5 projects here:
https://github.com/angular/angular-cli/issues/3875
https://github.com/angular/angular-cli/issues/8677
https://github.com/angular/angular-cli/issues/9376
有人知道怎么解决吗?
更新:
它似乎与 npm link
本身或符号链接无关.如果我只是将本地目录复制到 node_modules/sce-plugins
,我会得到同样该死的错误.然而,如果我 npm install
sce-plugins 到 node_modules 中,那么我不会得到错误.很奇怪,好像和angular-cli有关,而不是NPM.
It does not seem to have do with npm link
perse, or symlinks. If I simply copy the local directory over to node_modules/sce-plugins
, I get the same damn error. Yet, if I npm install
sce-plugins into node_modules then I do not get the error. Very strange, seems like it has to do with angular-cli, not NPM.
推荐答案
所以在再次阅读这个 Github 问题后:https://github.com/angular/angular-cli/issues/8284
So after reading this Github issue again: https://github.com/angular/angular-cli/issues/8284
我在 .angular-cli.json
中做了这个改动:
I made this change in .angular-cli.json
:
"defaults": {
"build": {
"preserveSymlinks": true // <<<< add this
},
"styleExt": "scss",
"component": {
}
}
现在,鉴于 preserveSymlinks
标志和我的 tsconfig.app.json
文件中的包含字段:
and now, given that preserveSymlinks
flag and the include field in my tsconfig.app.json
file:
"include":[
"./**/*.ts",
"../node_modules/sce-plugins/**/*.ts"
],
我现在可以将 'sce-plugins'
符号链接到我的主项目中,而不是手动复制文件.您可能根本不需要 "include"
字段,尽管我发现如果删除 "include"
字段,它将不起作用.
I can now symlink 'sce-plugins'
into my main project, instead of manually copying the files. It's possible that you won't need the "include"
field at all, although I found that if I removed the "include"
field, that it wouldn't work.
这篇关于缺少 *.ts 文件(由于 `npm link` ?)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!