【问题标题】:ng build --prod fails when I tried importing a javascript file in app-module当我尝试在 app-module 中导入 javascript 文件时,ng build --prod 失败
【发布时间】:2019-01-28 06:45:09
【问题描述】:

我必须在我的应用模块中导入一个 javascript 文件

import { OtherComponent } from './node_modules/blahblah/OtherComponent.js'

请注意,此 OtherComponent 已经是一个 javascript 文件。

然后在我的@NgModule 中,我将此组件添加到我的声明中。

当我运行“ng build --prod”时,它给了我错误:

ERROR 模块声明的意外值“OtherComponent” '应用模块'

请添加@Pipe/@Directive/@Component 注解

有没有办法解决这个问题?当我无权访问 OtherComponent 的 ts 文件时。

【问题讨论】:

    标签: javascript angular angular6 aot ng-build


    【解决方案1】:

    你不应该像这样导入 JS 文件。

    在 angular-cli.json 文件中。

    “脚本”:[ "./node_modules/blahblah/OtherComponent.js" ];

    然后重新启动您的项目。这应该可以完成工作。

    【讨论】:

    • 好的。不过,这个 OtherComponent 必须在 appmodule 中声明,以便我可以在整个应用程序中使用它。这可能吗?
    • 好的。为此,将其添加到 typings.d.ts declare var OtherComponent:any;将其作为 import * as otherComponent from 'OtherComponent' 导入到您的文件中;
    • 还是没有运气。当我从“OtherComponent”导入 * 作为 otherComponent 时,无法识别“OtherComponent”
    猜你喜欢
    • 2019-05-08
    • 2019-11-05
    • 2017-12-30
    • 1970-01-01
    • 1970-01-01
    • 2019-12-29
    • 1970-01-01
    • 2016-06-21
    • 2017-03-14
    相关资源
    最近更新 更多