缺少* .ts文件(由于`npm link`吗?) [英] Missing *.ts files (due to `npm link` ?)
问题描述
我在Angular5项目中有此import语句:
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中,那么我 not 不会收到错误.很奇怪,似乎与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
中进行了更改:
"defaults": {
"build": {
"preserveSymlinks": true // <<<< add this
},
"styleExt": "scss",
"component": {
}
}
现在,考虑到preserveSymlinks
标志和我的tsconfig.app.json
文件中的include字段:
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屋!