首页 > 解决方案 > Angular 5 错误:尝试从 node_modules /node_modules/ngx-bootstrap/typeahead/typeahead-container.component.ngfactory.ts 导入源文件

问题描述

你有什么建议,想法,我该如何解决以下错误?

这发生在我运行生产构建时。当我使用 -aot=false 运行生产构建时,更有趣的是它是成功的。

错误:错误:尝试从 node_modules 包中导入源文件:从 C:.../node_modules/ngx-bootstrap/typeahead/typeahead-container.component 导入 C:...search-scrollbar.directive.ts。 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) at 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) at templateVisitAll (C:...\node_modules\@angular\compiler\bundles\compiler.umd.js:1367:10)

标签: buildcompiler-errorsangular5ngx-bootstrapaot

解决方案


您正在导入源*.ts文件而不是编译*.js文件。确保你真的需要它。如果是 - 尝试在和/或文件中启用preserveSymlinks: true选项。在我的情况下,它解决了这个错误。angular.jsontsconfig.json


推荐阅读