question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ng build throw error - Cannot assign value "data" to template variable "permission". Template variables are read-only.

See original GitHub issue

🐞 bug report

Yes, the previous Angular version 8 this error was not present.

Description

After I update my angular project from 8 to 9 and execute the build node --max-old-space-size=5196 node_modules/@angular/cli/bin/ng build mgmt-console --prod --aot --build-optimizer --vendor-chunk

I gut this error: Cannot assign value “data” to template variable “permission”. Template variables are read-only.

The problem is the error doesn’t tel me which template file has this issue. (Below I added the entire error log)

I search manually in all my project for this text >> ‘[permission]’ and readonly permission and even something like that ‘=“data”’ unfortunately I didn’t found any of those.

🔥 Exception or Error


ERROR in Error: Cannot assign value "data" to template variable "permission". Template variables are read-only.
    at _AstToIrVisitor.visitPropertyWrite (/Users/ofirf/dev/management/mgmt-console/node_modules/@angular/compiler/bundles/compiler.umd.js:8626:31)
    at PropertyWrite.visit (/Users/ofirf/dev/management/mgmt-console/node_modules/@angular/compiler/bundles/compiler.umd.js:7519:28)
    at convertActionBinding (/Users/ofirf/dev/management/mgmt-console/node_modules/@angular/compiler/bundles/compiler.umd.js:8229:49)
    at prepareEventListenerParameters (/Users/ofirf/dev/management/mgmt-console/node_modules/@angular/compiler/bundles/compiler.umd.js:17117:27)
    at Object.params (/Users/ofirf/dev/management/mgmt-console/node_modules/@angular/compiler/bundles/compiler.umd.js:18226:24)
    at /Users/ofirf/dev/management/mgmt-console/node_modules/@angular/compiler/bundles/compiler.umd.js:17999:94
    at Array.map (<anonymous>)
    at /Users/ofirf/dev/management/mgmt-console/node_modules/@angular/compiler/bundles/compiler.umd.js:17999:60
    at /Users/ofirf/dev/management/mgmt-console/node_modules/@angular/compiler/bundles/compiler.umd.js:17273:87
    at Array.map (<anonymous>)
    at TemplateDefinitionBuilder.buildTemplateFunction (/Users/ofirf/dev/management/mgmt-console/node_modules/@angular/compiler/bundles/compiler.umd.js:17273:60)
    at /Users/ofirf/dev/management/mgmt-console/node_modules/@angular/compiler/bundles/compiler.umd.js:17809:60
    at /Users/ofirf/dev/management/mgmt-console/node_modules/@angular/compiler/bundles/compiler.umd.js:17251:81
    at Array.forEach (<anonymous>)
    at TemplateDefinitionBuilder.buildTemplateFunction (/Users/ofirf/dev/management/mgmt-console/node_modules/@angular/compiler/bundles/compiler.umd.js:17251:37)
    at /Users/ofirf/dev/management/mgmt-console/node_modules/@angular/compiler/bundles/compiler.umd.js:17809:60

🌍 Your Environment

Angular Version:





Anything else relevant?

Angular CLI: 9.1.0 Node: 12.3.1 OS: darwin x64

Angular: 9.1.0 … animations, cli, common, compiler, compiler-cli, core, forms … language-service, platform-browser, platform-browser-dynamic … platform-server, router, service-worker Ivy Workspace: Yes

Package Version

@angular-devkit/architect 0.901.0 @angular-devkit/build-angular 0.901.0 @angular-devkit/build-optimizer 0.901.0 @angular-devkit/build-webpack 0.901.0 @angular-devkit/core 9.1.0 @angular-devkit/schematics 9.1.0 @angular-devkit/schematics-cli 0.803.25 @angular/cdk 9.2.0 @angular/material 9.2.0 @ngtools/webpack 9.1.0 @nguniversal/express-engine 8.2.6 @schematics/angular 9.1.0 @schematics/schematics 0.803.25 @schematics/update 0.901.0 rxjs 6.5.4 typescript 3.8.3 webpack 4.42.0 please mention it below. -->

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
JoeFirebaughcommented, Jul 30, 2020

FWIW, I found that making this change in node_modules/@angular/compiler/bundles/compiler.umd.js at line 8923 gave me the filename I needed to fix it. I had quite a few due to my project having been written before AOT.

var filePath = this._localResolver.component.filePath;
throw new Error("Cannot assign value \"" + value + "\" to template variable \"" + receiver_1 + "\". Template variables are read-only. : " + filePath);

YMMV.

I did notice that same line of code is in several places within the compiler project, so you might have to fix it elsewhere too.

1reaction
JoostKcommented, Mar 30, 2020

@ofirrifo Please see https://github.com/angular/angular/issues/35139#issuecomment-581850479 for how this can be caught the nice way.

The error occurs in a part of the compiler where dealing with such errors is a bit problematic. The template type checker is able to catch this case and properly report a diagnostic, but if it’s disabled then you’ll end up with this error 😦

Read more comments on GitHub >

github_iconTop Results From Across the Web

strange problem migrating angular 8 app to 9 - Stack Overflow
As the error suggests, template variables are read-only so you cannot bind your model to template variables, instead you can bind to ...
Read more >
DateBox - Throws an error "Template variables are read-only."
The error: Error: Cannot assign value "$event" to template variable "v". Template variables are read-only. at _AstToIrVisitor.
Read more >
cannot assign value $event'' to template variable
ERROR Error : Cannot assign value "$event" to template variable "nameValue". Template variables are read-only. For example, to assign the value of an ......
Read more >
Understanding template variables - Angular
Template variables help you use data from one part of a template in ... Angular assigns a template variable a value based on...
Read more >
Template-Driven Forms • Angular - codecraft.tv
In this lecture we'll be converting the model-driven form we've been building so far in this section into a template-driven form.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found