你有什么建议,想法,我该如何解决以下错误?
这发生在我运行生产构建时。
当我使用 -aot=false 运行生产构建时,更有趣的是它是成功的。
错误:错误:尝试从 node_modules 包中导入源文件:从 C 中导入 C:...search-scrollbar.directive.ts:
.../node_modules/ngx-bootstrap/typeahead/typeahead-container.component.ngfactory.ts
在 TsCompilerAotCompilerTypeCheckHostAdapter.fileNameToModuleName (C:...\node_modules\@angular\compiler-cli\src\transformers\compiler_host.js:187:19)
在 AotCompiler._fileNameToModuleName (C:...\node_modules\@angular\compiler\bundles\compiler.umd.js:31099:24)
在 Object.importExpr$$1 [as importExpr] (C:...\node_modules\@angular\compiler\bundles\compiler.umd.js:31067:55)
在 singleProviderDef (C:...\node_modules\@angular\compiler\bundles\compiler.umd.js:20028:28)
在 providerDef (C:...\node_modules\@angular\compiler\bundles\compiler.umd.js:19962:9)
在 ViewBuilder._visitProviderOrDirective (C:...\node_modules\@angular\compiler\bundles\compiler.umd.js:28177:18)
在 ViewBuilder._visitDirective (C:...\node_modules\@angular\compiler\bundles\compiler.umd.js:28025:23)
在 C:...\node_modules\@angular\compiler\bundles\compiler.umd.js:27926:32
在 Array.forEach ( native )
在 ViewBuilder._visitElementOrTemplate (C:...\node_modules\@angular\compiler\bundles\compiler.umd.js:27916:23)
在 ViewBuilder.visitElement (C:...\node_modules\@angular\compiler\bundles\compiler.umd.js:27820:23)
在 ElementAst.visit (C:...\node_modules\@angular\compiler\bundles\compiler.umd.js:925:24)
访问时(C:...\node_modules\@angular\compiler\bundles\compiler.umd.js:1366:37)
在 C:...\node_modules\@angular\compiler\bundles\compiler.umd.js:1368:42
在 Array.forEach ( native )
在 templateVisitAll (C:...\node_modules\@angular\compiler\bundles\compiler.umd.js:1367:10)
最佳答案
您正在导入源 *.ts
文件而不是编译 *.js
文件。确保你真的需要它。如果是,请尝试启用 preserveSymlinks: true
angular.json
中的选项和/或 tsconfig.json
文件。在我的情况下,它解决了这个错误。
关于build - Angular 5 错误 :Trying to import a source file from a node_modules/node_modules/ngx-bootstrap/typeahead/typeahead-container. component.ngfactory.ts,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50408354/