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

2024-01-02

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

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 存储库来修复它。

  1. 错误消息中没有详细信息:issue https://github.com/angular/angular/issues/32759, PR https://github.com/angular/angular/pull/32760
  2. 为模板变量赋值会导致产品构建崩溃:issue https://github.com/angular/angular/issues/32761, PR https://github.com/angular/angular/pull/32762

碰巧 AST 解析器的大多数异常都是令人头疼的。只是因为它们不携带任何有用的东西,除了一条消息:

错误无法分配给引用或变量!

哦真的吗?

例如,链接器 (ViewBuilder) 总是写在无法构建模板表达式的地方。

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


第二个选项有点硬编码。值得深入了解编译器本身并进行调试。角度用途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!');

抛出异常时根本没有任何信息????

让我们添加console.log(ast)在异常之前,其中ast是的参数visitPropertyWrite功能。解析器将记录一个实例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)] there.

至少你知道该走哪条路:)

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

无法分配给引用或变量中的 Angular 产品构建错误 的相关文章

随机推荐

  • 如何在 Emacs/elisp 风格的正则表达式中用“\(”替换“(”?

    问题如标题 更具体地说 我厌倦了打字 等等 每次我想在 Emacs 的 交互式 正则表达式函数中使用括号 更不用说 在代码中 所以我写了类似的东西 defadvice query replace regexp before my query
  • MvvmCross Xamarin.Forms 模态对话框

    我只是想用 MvvmCross 制作我的第一个应用程序 但我的应用程序已经遇到了问题 并且在网络上找不到任何相关内容 我想在支持的设备 例如 iPad 上打开特定页面作为模式对话框 对于我的非 MvvmCross 应用程序 我使用 Rg P
  • 如何使用 Bootstrap 3 模态来实现 JavaScriptalert()?

    如果我的 HTML 标头中的 JavaScript 代码中有警报 例如 有没有办法可以使用 Bootstrap 中的模式窗口而不是浏览器的本机警报窗口 如果是这样 有人可以向我展示上面一行代码的简单示例吗 模式应该只有一个 确定 按钮 没什
  • p5.j​​s 中的上下移动(并使用 WASD)

    在p5中如何使用键盘让角色移动 我的意思是 不仅仅是向左和向右 我还想使用 WASD 键 我用过这个 形状作为占位符 https editor p5js org TheDiamondfinderYT present 8ZqV2LsVB ht
  • 如何用Pickle存储自我价值?

    class Player def init self self money 0 self level 0 self xp 0 self xp until level 20 self taxi car Cabbie self busines
  • 在 Jenkins 中配置 GitLab 存储库

    我正在尝试配置 Jenkins 在 Windows Server 2008 上运行 以连接到 GitLab 6 0 存储库 在 Linux 机器上 从我的本地 Windows 盒子中 我可以使用 SSH URL 来克隆我的 GitLab 服
  • 将参数传递给另一个可变参数函数

    有没有什么方法可以让这段代码按预期编译和工作 而无需求助于va list stuff include
  • Android LVL(许可服务)非常慢! ——解决方案?异步?

    我在网上查了一下 看到其他一些帖子抱怨 Android 许可 LVL 库如何缓慢 但没有解决方案 在 HTC Thunderbolt 全新手机 上 它会使测试应用程序的启动时间延迟 3 5 秒以上 有人对异步调用这个库有任何经验或想法吗 其
  • 如何让 Eclipse 自动生成新 Java 类的 main 方法?

    有谁知道我的 Eclipse 不预加载的原因 public static void main String args 当我创建一个新课程时 我该怎么做才能让它自动出现 Type main and press ctrl space The e
  • 提取 Windows 中任何文件的缩略图

    从任何文件 而不仅仅是不同大小的图像 中提取缩略图的最有效方法是什么 我已经查看了所有内容 其中最有希望的是 Windows API ShellFile 但它似乎没有正确安装 我使用的是Windows 7 不久前 我编写了一个 Thumbn
  • 这些 Linux 内核 Oops 字段的含义是什么?

    我在开发人员的生活中已经遇到过一些 Oops 虽然我熟悉可以从这些 Oops 中检索到的一些信息 但仍然有一些信息我无法理解 因此无法用来解决问题 下面您将找到一个 Oops 示例 我将描述我可以从中推断出什么 然后 我会问剩下的信息可以告
  • Django在syncdb时以自定义方式初始化数据库

    我在开发过程中使用 Django 令人烦恼的是 每次我对模型进行一点更改时 我都需要删除数据库并运行syncdb 为了测试的目的 我想每次运行syncdb时自动将一些初始数据添加到数据库中 我尝试将这些代码放入一个应用程序中 init py
  • bash:如何在没有 date -d 选项的情况下比较 Solaris 上的两个日期

    我试图将日志文件行中输入的日期与昨天的日期进行比较 如果差异超过一天 则它会打印日志文件中的该行 日志档案 more ActiveX2Alarms log 2016 09 30 01 40 14 MET faultManager netwo
  • 为什么我可以在私有类型上使用 auto?

    我对以下代码的编译和运行感到惊讶 vc2012 gcc4 7 2 class Foo struct Bar int i public Bar Baz return Bar int main Foo f Foo Bar b f Baz err
  • 如何将 Excel 配色方案从一个工作簿复制到另一个工作簿

    有时 当我从一个工作簿复制并粘贴到另一个工作簿时 目标配色方案看起来很奇怪 如何将配色方案从一个工作簿复制到另一个工作簿 打开 VBA 并键入以下内容 根据需要更改工作簿的名称 workbooks DestinationWorkbook x
  • 获取手机中安装的所有社交媒体应用程序的列表?

    我正在开发一个应用程序 其中列出了用户移动设备中安装的所有应用程序 我检索了所有应用程序并将其列出在回收视图 现在我想将社交媒体应用程序从该列表中分离出来以用于其他目的 有什么办法可以分离社交媒体应用程序吗 我使用下面的代码从手机检索所有应
  • 何时使用 代替

    正如问题所示 如果我想在 HTML 中添加一些文本 那么我应该何时使用 p 我什么时候应该使用 span 您应该记住 HTML 旨在描述它包含的内容 所以 如果你想传达一段话 那就这么做吧 不过 您的比较并不完全正确 更直接的比较是 何时使
  • 有没有办法用带参数的sql脚本运行impala shell?

    有没有办法使用带参数的 SQL 脚本运行 impala shell 例如 impala shell f home john sql load sql dir1 dir2 dir3 data file 我收到错误 错误 无法解析参数 f ho
  • 流浪者警告:连接被拒绝。重试

    测试默认示例 vagrant init hashicorp precise32 vagrant up 我的盒子 视窗8 1 虚拟盒 5 0 2 流浪者1 7 4 Intel i7 4700MQ CPU 似乎具有 Intel 虚拟化技术 VT
  • 无法分配给引用或变量中的 Angular 产品构建错误

    我无法构建我的角度应用程序的产品版本 IDE 控制台中只有此消息 错误无法分配给引用或变量 所以我只有添加这些选项才能构建 aot false buildOptimizer false 但是 即使使用这些选项 应用程序在部署后也会失败 并在