gpt4 book ai didi

无法分配给引用或变量中的 Angular 产品生成错误

转载 作者:行者123 更新时间:2023-12-03 16:29:27 25 4
gpt4 key购买 nike

我无法构建我的 Angular 应用程序的产品版本。

并且在IDE控制台中只有以下消息:

ERROR in Cannot assign to a reference or variable!



因此,只有添加以下选项,我才能进行构建:
--aot=false --buildOptimizer=false

但是,即使有这些选项,应用程序在浏览器控制台中部署并显示以下消息后也会失败:

ERROR TypeError: Cannot read property 'init' of undefined



可以通过添加另一个选项将其设置为 fixed:
--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 npm@6.10.2
3 info using node@v10.15.3
4 verbose run-script [ 'preng', 'ng', 'postng' ]
5 info lifecycle dont-play-with-gp-web@0.0.2~preng: dont-play-with-gp-web@0.0.2
6 info lifecycle dont-play-with-gp-web@0.0.2~ng: dont-play-with-gp-web@0.0.2
7 verbose lifecycle dont-play-with-gp-web@0.0.2~ng: unsafe-perm in lifecycle true
8 verbose lifecycle dont-play-with-gp-web@0.0.2~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 dont-play-with-gp-web@0.0.2~ng: CWD: C:\DEV\WebStormProjects\dont-play-with-gp-web
10 silly lifecycle dont-play-with-gp-web@0.0.2~ng: Args: [ '/d /s /c', 'ng "build" "--prod"' ]
11 silly lifecycle dont-play-with-gp-web@0.0.2~ng: Returned: code: 1 signal: null
12 info lifecycle dont-play-with-gp-web@0.0.2~ng: Failed to exec ng script
13 verbose stack Error: dont-play-with-gp-web@0.0.2 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 dont-play-with-gp-web@0.0.2
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 dont-play-with-gp-web@0.0.2 ng: `ng "build" "--prod"`
22 error Exit status 1
23 error Failed at the dont-play-with-gp-web@0.0.2 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

还有我的 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

关于 ru.stackoverflow的相同问题: https://ru.stackoverflow.com/questions/1025395

SOVLED:

最后,我有一个错误原因(用户 https://stackoverflow.com/users/10123947/shadow找到了它):有人尝试更改模板中变量的值,该模板是在自制指令的帮助下定义的。

问题出在错误消息中。提到的用户仅通过调试编译器收到详细信息(据我了解)。有一些详细信息(俄语): https://ru.stackoverflow.com/a/1025417/17609

更新:

我将问题和PR添加到了 Angular 存储库中进行修复。
  • 错误消息中没有详细信息:issuePR
  • 为模板变量分配值会导致产品构建崩溃:issuePR
  • 最佳答案

    碰巧,AST分析器中的大多数异常令人头疼。只是因为它们没有任何有用的信息,只不过是一条消息而已:

    ERROR in Cannot assign to a reference or variable!



    哦真的吗?

    例如,链接器( ViewBuilder)始终在无法构建模板表达式的位置进行写操作。

    谷歌搜索可能是解决方案之一。但是,由于大多数答案将提供检查模板中 ngModel指令用法的事实,整个圈子将被封闭。

    第二个选择是一些硬编码。值得进入编译器本身并进行调试。 Angular在编译过程中使用 node_modules/@angular/compiler/bundles/compiler.umd.js

    让我们打开此文件,然后尝试搜索文本 Cannot assign to a reference or variable!。我们将找到 _AstToIrVisitor类和 visitPropertyWrite方法。有这样一行代码
    // Otherwise it's an error.
    throw new Error('Cannot assign to a reference or variable!');

    完全没有任何信息就抛出异常🤨

    让我们在异常(exception)之前添加 console.log(ast),其中 astvisitPropertyWrite函数的参数。解析器会将 PropertyWrite类的实例记录到控制台:
    PropertyWrite {
    span: ParseSpan { start: 0, end: 73 },
    receiver: ImplicitReceiver { span: ParseSpan { start: 0, end: 0 } },
    name: 'translation',
    value: MethodCall {
    span: ParseSpan { start: 14, end: 73 },
    receiver: ImplicitReceiver { span: [ParseSpan] },
    name: 'getTranslationForLanguageFromArticle',
    args: [ [PropertyRead], [PropertyRead] ]
    }
    }

    我们得出的结论是,我们必须了解 translation属性和 getTranslationForLanguageFromArticle方法调用之间的关系。当我尝试从Bitbucket克隆您的示例时,我寻找了“getTranslationForLanguageFromArticle”用法,并在 feed.component.html中找到了这一行:
    (change)="translation = getTranslationForLanguageFromArticle($event.value, article)"

    这是解析器无法理解的,因为 translation不是类属性。这是在 ng-template指令中隐式访问的本地 *ngVar变量。

    我会在组件内部创建类似 changeTranslation的方法,并在那里使用 article.translations[indexOfCorrectArticleTranslation(article)]进行操作。

    至少你知道走哪条路:)

    关于无法分配给引用或变量中的 Angular 产品生成错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57978475/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com