Angular 8 - ng build prod 在 ng serve 工作时显示错误 - 模块导入的意外值“未定义”
Posted
技术标签:
【中文标题】Angular 8 - ng build prod 在 ng serve 工作时显示错误 - 模块导入的意外值“未定义”【英文标题】:Angular 8 - ng build prod shows errors while ng serve works - Unexpected value 'undefined' imported by the module 【发布时间】:2020-01-26 04:37:44 【问题描述】:我的应用程序在使用ng serve
时构建和运行良好,但在使用ng build --prod
时显示错误。该错误位于/node_modules/
下的依赖项中,因此不确定如何解决?
错误信息:
ERROR in Unexpected value 'undefined' imported by the module 'ExampleModule in /Users/Projects/KagiDocs/git/core/node_modules/@angular/material-examples/examples_public_index.d.ts'
package.json
...
"private": true,
"dependencies":
"@angular/animations": "^8.0.0",
"@angular/cdk": "^8.1.4",
"@angular/cdk-experimental": "^8.1.1",
"@angular/common": "^8.0.0",
"@angular/compiler": "^8.0.0",
"@angular/core": "^8.0.0",
"@angular/forms": "^8.0.0",
"@angular/material": "^8.1.4",
"@angular/material-examples": "angular/material2-docs-content#8.1.x",
"@angular/material-experimental": "^8.1.1",
"@angular/material-moment-adapter": "^8.1.4",
"@angular/platform-browser": "^8.0.0",
"@angular/platform-browser-dynamic": "^8.0.0",
"@angular/router": "^8.0.0",
"core-js": "^2.6.1",
"hammerjs": "^2.0.8",
"material-components-web": "^1.1.1",
"moment": "^2.23.0",
"rxjs": "^6.5.1",
"zone.js": "^0.9.0"
,
"devDependencies":
"@angular-devkit/build-angular": "^0.800.0",
"@angular/cli": "^8.0.0",
"@angular/compiler-cli": "^8.0.0",
"@types/jasmine": "^3.3.5",
"@types/node": "^10.12.18",
"firebase-tools": "^6.2.2",
"jasmine-core": "~2.99.1",
"jasmine-spec-reporter": "~4.2.1",
"karma": "^3.1.4",
"karma-chrome-launcher": "^2.2.0",
"karma-firefox-launcher": "^1.1.0",
"karma-jasmine": "^1.1.2",
"karma-jasmine-html-reporter": "^0.2.2",
"node-sass": "^4.11.0",
"protractor": "~5.3.0",
"ts-node": "^6.0.3",
"tslint": "^5.10.0",
"typescript": "3.4"
我们已经 .克隆了这个 https://github.com/angular/material.angular.io 代码库来构建我们的项目。
【问题讨论】:
您在最终构建中是否需要@angular/material-examples
,或者您可以仅将其移至开发依赖项?
我不知道(按照这个 repo 作为参考 github.com/angular/material.angular.io)。但我试图移动它并使用 ng build --prod
重建,同样的问题。
尝试删除 node_modules 目录的内容,然后使用“npm install”重新安装模块
试过了..没有帮助:(
【参考方案1】:
我们能够解决问题,发布解决方案以供参考:
按照https://github.com/angular/material.angular.io/issues/629中的建议,将package.json
中angular/material2-docs-content
的版本更新为
"@angular/material-examples": "angular/material2-docs-content#8.0.x",
修复了问题。
使用时有问题:
"@angular/material-examples": "angular/material2-docs-content#8.1.x",
【讨论】:
以上是关于Angular 8 - ng build prod 在 ng serve 工作时显示错误 - 模块导入的意外值“未定义”的主要内容,如果未能解决你的问题,请参考以下文章
Angular 8:运行 ng build --prod --base-href './project1' 时访问资产文件夹
Angular:仅在 ng build --prod 上构建 ES2015