jquery - 将应用程序迁移到 Angular 6 : But getting errors while running npm run build --prod. 但命令 npm run build --env=prod 成功运行

标签 jquery node.js angular typescript npm

当我使用命令 npm run build -- --prod 时,我收到以下错误消息:

  • 属性“PropertyName1”是私有(private)属性,只能在“AppComponent”类中访问
  • “AppComponent”类型中不存在属性“PropertyName2”

ERROR in src\app\components\app\app.component.html(77,56): : Property 'validate' is private and only accessible within class 'AppComponent'. src\app\components\entitysearchlight\entitysearchlight.component.html(3,157): : Property 'loadingMessage' is private and only accessible within class 'EntitySearchLightComponent'. src\app\components\entitysearchlight\entitysearchlight.component.html(23,91): : Expected 0 arguments, but got 1. src\app\components\entitysearchlight\entitysearchlight.component.html(97,62): : Property 'e' does not exist on type 'EntitySearchLightComponent'. src\app\components\search\search.component.html(3,157): : Property 'loadingMessage' is private and only accessible within class 'SearchComponent'. src\app\components\search\search.component.html(23,91): : Expected 0 arguments, but got 1. src\app\components\search\search.component.html(57,43): : Property 'onFilterItemSelect' is private and only accessible within class 'SearchComponent'. src\app\components\search\search.component.html(90,58): : Property 'e' does not exist on type 'SearchComponent'.

当我运行时,相同的应用程序成功构建:npm run build --env=prod

您能否告诉我这两个命令如何导致构建过程或配置发生变化?

最佳答案

正如上面所写,您需要将访问修饰符 private 更改为 public。您有一些必要的小文件。但是,您需要避免功能上的问题。

我建议使用 tslint 并检查您的代码。添加tslint.json新规则

"rules": {
...
    "member-access": true,

并在各处添加访问修饰符。

package.json中创建命令,您可以在其中检查构建

 "scripts": {
    "lint": "ng lint",
     ...
    "building:prod": "npm i && ng lint && ng build --prod"
  },

关于jquery - 将应用程序迁移到 Angular 6 : But getting errors while running npm run build --prod. 但命令 npm run build --env=prod 成功运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54983825/

相关文章:

javascript - 如何使用DataTables处理onclick事件?

node.js - 使用 docker 镜像的 Azure Linux 应用服务中的 Mongo 连接错误

javascript - Angular2 Dropdown 恢复到以前选择的选项

angular - ionic点击事件获取元素

angular - 如何从 Firebase 存储中获取图像并在 Angular 2 ngFor 中显示它们

jquery - 如何使用 jQuery 发出 AJAX HTTPS GET 请求

javascript - 修改内存中的 Jquery 元素并返回它

javascript - 为什么我无法从此 jsonp 响应获取位置?

json - 将 XML 字符串转换为 JSON

node.js - NPM 安装个人 Node 库