Working on an Angular/CLI/TypeScript 2.3 project, I encountered a common error type:
TypeError: Cannot assign to read only property 'myValue' of object '#'
This issue usually arises when there's an attempt to modify a property of an object declared with a const
. However, the cause of this problem is not my main concern here.
My question pertains to why these errors are visible only after executing ng build
and not during local development using ng serve
. Is it possible to make them appear during ng serve
as well?
Edit
It seems like the 'use strict'
declaration gets injected into the compiled code but is missing from the code executed by Webpack while running ng serve
.
Citing a relevant observation made in this blog post comment:
const foo = 27;
// The following lines will result in an exception.
// Assignment operators:
foo = 42;
However, including the statement below before declaring the constant circumvents the issue:
'use strict';
const foo = 27;
// The following lines will result in an exception.
// Assignment operators:
foo = 42;