我无法构建我的角度应用程序的产品版本。
IDE 控制台中只有此消息:
错误无法分配给引用或变量!
所以我只有添加这些选项才能构建:
--aot=false --buildOptimizer=false
但是,即使使用这些选项,应用程序在部署后也会失败,并在浏览器控制台中显示以下消息:
错误类型错误:无法读取未定义的属性“init”
这可以是fixed https://github.com/angular/flex-layout/issues/950添加一个选项:
--optimization=false
当我尝试构建时
npm run ng build -- --prod
我有一个包含一些信息的日志文件:
0 info it worked if it ends with ok
1 verbose cli [ 'C:\\Backend\\nodejs\\node.exe',
1 verbose cli 'C:\\Users\\USER_NAME\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js',
1 verbose cli 'run',
1 verbose cli 'ng',
1 verbose cli 'build',
1 verbose cli '--',
1 verbose cli '--prod' ]
2 info using [email protected] /cdn-cgi/l/email-protection
3 info using [email protected] /cdn-cgi/l/email-protection
4 verbose run-script [ 'preng', 'ng', 'postng' ]
5 info lifecycle [email protected] /cdn-cgi/l/email-protection~preng: [email protected] /cdn-cgi/l/email-protection
6 info lifecycle [email protected] /cdn-cgi/l/email-protection~ng: [email protected] /cdn-cgi/l/email-protection
7 verbose lifecycle [email protected] /cdn-cgi/l/email-protection~ng: unsafe-perm in lifecycle true
8 verbose lifecycle [email protected] /cdn-cgi/l/email-protection~ng: PATH: C:\Users\USER_NAME\AppData\Roaming\npm\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin;C:\DEV\WebStormProjects\dont-play-with-gp-web\node_modules\.bin;C:\DEV\WebStormProjects\dont-play-with-gp-web\node_modules\.bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Program Files\Git\cmd;C:\Backend\IntelliJ IDEA 2018.3.5\jre64;C:\Backend\PostgreSQL\10\bin;C:\Backend\nodejs;C:\Backend\WinSCP\;C:\Android\sdk\platform-tools;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Users\USER_NAME\AppData\Local\Microsoft\WindowsApps;
9 verbose lifecycle [email protected] /cdn-cgi/l/email-protection~ng: CWD: C:\DEV\WebStormProjects\dont-play-with-gp-web
10 silly lifecycle [email protected] /cdn-cgi/l/email-protection~ng: Args: [ '/d /s /c', 'ng "build" "--prod"' ]
11 silly lifecycle [email protected] /cdn-cgi/l/email-protection~ng: Returned: code: 1 signal: null
12 info lifecycle dont-play-[email protected] /cdn-cgi/l/email-protection~ng: Failed to exec ng script
13 verbose stack Error: [email protected] /cdn-cgi/l/email-protection ng: `ng "build" "--prod"`
13 verbose stack Exit status 1
13 verbose stack at EventEmitter.<anonymous> (C:\Users\USER_NAME\AppData\Roaming\npm\node_modules\npm\node_modules\npm-lifecycle\index.js:326:16)
13 verbose stack at EventEmitter.emit (events.js:189:13)
13 verbose stack at ChildProcess.<anonymous> (C:\Users\USER_NAME\AppData\Roaming\npm\node_modules\npm\node_modules\npm-lifecycle\lib\spawn.js:55:14)
13 verbose stack at ChildProcess.emit (events.js:189:13)
13 verbose stack at maybeClose (internal/child_process.js:970:16)
13 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:259:5)
14 verbose pkgid [email protected] /cdn-cgi/l/email-protection
15 verbose cwd C:\DEV\WebStormProjects\dont-play-with-gp-web
16 verbose Windows_NT 10.0.17134
17 verbose argv "C:\\Backend\\nodejs\\node.exe" "C:\\Users\\USER_NAME\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js" "run" "ng" "build" "--" "--prod"
18 verbose node v10.15.3
19 verbose npm v6.10.2
20 error code ELIFECYCLE
21 error errno 1
22 error [email protected] /cdn-cgi/l/email-protection ng: `ng "build" "--prod"`
22 error Exit status 1
23 error Failed at the [email protected] /cdn-cgi/l/email-protection ng script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]
我尝试更新所有内容,但没有帮助。
这是结果ng version
:
Angular CLI: 8.3.4
Node: 10.15.3
OS: win32 x64
Angular: 8.2.6
... animations, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router
Package Version
-----------------------------------------------------------
@angular-devkit/architect 0.803.4
@angular-devkit/build-angular 0.803.4
@angular-devkit/build-optimizer 0.803.4
@angular-devkit/build-webpack 0.803.4
@angular-devkit/core 8.3.4
@angular-devkit/schematics 8.3.4
@angular/cdk 8.2.0
@angular/cli 8.3.4
@angular/flex-layout 8.0.0-beta.27
@angular/material 8.2.0
@ngtools/webpack 8.3.4
@schematics/angular 8.3.4
@schematics/update 0.803.4
rxjs 6.5.3
typescript 3.5.3
webpack 4.39.2
And my package.json
:
{
"name": "dont-play-with-gp-web",
"version": "0.0.2",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
"@angular/animations": "^8.2.6",
"@angular/cdk": "^8.2.0",
"@angular/common": "~8.2.6",
"@angular/compiler": "~8.2.6",
"@angular/core": "~8.2.6",
"@angular/flex-layout": "8.0.0-beta.27",
"@angular/forms": "~8.2.6",
"@angular/material": "^8.2.0",
"@angular/platform-browser": "~8.2.6",
"@angular/platform-browser-dynamic": "~8.2.6",
"@angular/router": "~8.2.6",
"angular-markdown-editor": "^2.0.2",
"hammerjs": "^2.0.8",
"jquery": "^3.4.1",
"ngx-infinite-scroll": "^8.0.0",
"ngx-markdown": "^8.1.0",
"ngx-material-file-input": "^2.0.0",
"rxjs": "~6.5.3",
"tslib": "^1.9.0",
"zone.js": "^0.9.1"
},
"devDependencies": {
"@angular-devkit/build-angular": "~0.803.4",
"@angular/cli": "~8.3.4",
"@angular/compiler-cli": "~8.2.6",
"@angular/language-service": "~8.2.6",
"@types/jasmine": "~3.4.0",
"@types/jasminewd2": "~2.0.3",
"@types/jquery": "^3.3.31",
"@types/node": "~12.7.5",
"codelyzer": "^5.0.0",
"jasmine-core": "~3.4.0",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~4.3.0",
"karma-chrome-launcher": "~3.1.0",
"karma-coverage-istanbul-reporter": "~2.1.0",
"karma-jasmine": "~2.0.1",
"karma-jasmine-html-reporter": "^1.4.0",
"protractor": "~5.4.0",
"ts-node": "~8.4.1",
"tslint": "~5.20.0",
"typescript": "^3.5.3"
}
}
那么,在这种情况下我能做什么呢?如何查找错误原因以及如何修复?
如果它可以帮助 - 这是我的源代码:
https://bitbucket.org/mohaxspb/gp-web/commits/tag/ATTEMPT_TO_FIX_PROD_BUILD_WITH_DEPS_UPDATE https://bitbucket.org/mohaxspb/gp-web/commits/tag/ATTEMPT_TO_FIX_PROD_BUILD_WITH_DEPS_UPDATE
同样的问题ru.stackoverflow
: https://ru.stackoverflow.com/questions/1025395 https://ru.stackoverflow.com/questions/1025395
SOVLED:
最后我有错误原因(所以用户https://stackoverflow.com/users/10123947/shadow https://stackoverflow.com/users/10123947/shadow找到了):有人尝试更改模板中变量的值,在自制指令的帮助下在模板中定义。
这里的问题在于糟糕的错误消息。提到的用户仅通过调试编译器收到详细信息(据我所知)。有一些细节(俄语):https://ru.stackoverflow.com/a/1025417/17609 https://ru.stackoverflow.com/a/1025417/17609
UPDATE:
我将问题和 PR 添加到 Angular 存储库来修复它。
- 错误消息中没有详细信息:issue https://github.com/angular/angular/issues/32759, PR https://github.com/angular/angular/pull/32760
- 为模板变量赋值会导致产品构建崩溃:issue https://github.com/angular/angular/issues/32761, PR https://github.com/angular/angular/pull/32762