在 ng build --prod 之后,为啥我在 main.js:1 和 polyfills.js:1 中出现错误,而不是在我创建的组件中,如何撤消这个?
Posted
技术标签:
【中文标题】在 ng build --prod 之后,为啥我在 main.js:1 和 polyfills.js:1 中出现错误,而不是在我创建的组件中,如何撤消这个?【英文标题】:After ng build --prod, why am I getting errors in main.js:1 and polyfills.js:1, rather than in components that I created, How to undo this?在 ng build --prod 之后,为什么我在 main.js:1 和 polyfills.js:1 中出现错误,而不是在我创建的组件中,如何撤消这个? 【发布时间】:2021-08-06 15:05:04 【问题描述】:我想部署一个几乎完成的 Angular 项目,为了部署,我执行了 ng build --prod。它创建了一个比我部署到服务器的 dist。一切都明白了,到这里为止,但是现在当我更改项目中的内容并执行“ng serve -o”时,我看不到我在编写这些 console.log 消息的那些组件中设置的控制台消息,而是这些被引用来自“main.js:1”和“polyfills.js:1”。
我仍然收到这些控制台消息,但我不知道它在控制台上打印在哪个组件中。
ERROR TypeError: Cannot read property 'UserzAccessStatus' of undefined
at main.js:1
at i.<computed> (polyfills.js:1)
at e.invokeTask (polyfills.js:1)
at Object.onInvokeTask (main.js:1)
at e.invokeTask (polyfills.js:1)
at t.runTask (polyfills.js:1)
at t.invokeTask (polyfills.js:1)
at invoke (polyfills.js:1)
at r.args.<computed> (polyfills.js:1)
chrome 控制台中的Console.log() 消息
package.json 文件
"name": "gbcl",
"version": "0.0.0",
"scripts":
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e",
"start:server": "nodemon server.js"
,
"private": true,
"dependencies":
"@angular/animations": "~12.0.0",
"@angular/common": "~12.0.0",
"@angular/compiler": "~12.0.0",
"@angular/core": "~12.0.0",
"@angular/forms": "~12.0.0",
"@angular/platform-browser": "~12.0.0",
"@angular/platform-browser-dynamic": "~12.0.0",
"@angular/router": "~12.0.0",
"bcrypt": "^5.0.1",
"body-parser": "^1.19.0",
"bootstrap": "^4.5.2",
"express": "^4.17.1",
"jquery": "^3.6.0",
"mongoose": "^5.12.8",
"mongoose-unique-validator": "^2.0.3",
"popper.js": "^1.16.1",
"rxjs": "~6.5.3",
"tslib": "^2.2.0",
"zone.js": "~0.11.4"
,
"devDependencies":
"@angular-devkit/build-angular": "~12.0.0",
"@angular/cli": "^12.0.0",
"@angular/compiler-cli": "^12.0.0",
"@types/jasmine": "~3.7.2",
"@types/jasminewd2": "~2.0.9",
"@types/node": "^15.0.3",
"codelyzer": "^6.0.2",
"jasmine-core": "~3.7.1",
"jasmine-spec-reporter": "~7.0.0",
"karma": "~6.3.2",
"karma-chrome-launcher": "~3.1.0",
"karma-coverage-istanbul-reporter": "~3.0.3",
"karma-jasmine": "~4.0.1",
"karma-jasmine-html-reporter": "^1.6.0",
"nodemon": "^2.0.7",
"protractor": "~7.0.0",
"ts-node": "~9.1.1",
"tslint": "~6.1.0",
"typescript": "~4.2.4"
tsconfig.app.json 文件
"extends": "./tsconfig.base.json",
"compilerOptions":
"outDir": "./out-tsc/app",
"types": []
,
"angularCompilerOptions":
"enableIvy": true,
"strictTemplates": true,
"strictInjectionParameters": true
,
"files": [
"src/main.ts",
"src/polyfills.ts"
],
"include": [
"src/**/*.d.ts"
]
如果需要有关任何文件的更多信息,请询问。
【问题讨论】:
刷新页面时是否还引用main.js
?
是的,每次我刷新它都是指 main.js
【参考方案1】:
在生产环境中查看错误的确切位置
ng build --prod --build-optimizer --sourceMap=true
你可以得到构建。
您的错误很可能是“?????????”您打印的对象名称中没有"UserzAccessStatus"
键。
【讨论】:
它没有帮助。【参考方案2】:您必须根据此回复更新 angular.json 中的服务配置部分
Angular 12 'ng serve' builds apps slowly, almost like production builds
【讨论】:
以上是关于在 ng build --prod 之后,为啥我在 main.js:1 和 polyfills.js:1 中出现错误,而不是在我创建的组件中,如何撤消这个?的主要内容,如果未能解决你的问题,请参考以下文章
如何在“ng build --prod”之后让我的 Angular 应用程序使用编辑过的配置文件
使用 ng build --prod 构建时出错。没有 --prod 标志和 ng serve 很好