Which @angular/* package(s) are the source of the bug?
core
Is this a regression?
Yes
Description
In our project, we have some angular services (that have a @Injectable({ providedIn: 'root' }) and an import { Injectable } from '@angular/core';)
During our CI process we re-use these services outside of our angular application to dynamically populate our test database.
We do this through calling these services in a ts-node script.
When upgrading to angular 13, when we do "ts-node populate.ts" we get:
POPULATE ERROR: Error [ERR_REQUIRE_ESM]: require() of ES Module C:\lander\devprojects\acro-companion\node_modules\@angular\core\fesm2015\core.mjs not supported.
Instead change the require of C:\lander\devprojects\acro-companion\node_modules\@angular\core\fesm2015\core.mjs to a dynamic import() which is available in all CommonJS modules.
Is this expected?
Do we need to change something to the tsconfig.json file (see below) with which we call the ts-node script?
This is expected. The Angular packages no longer contain CommonJS (UMD) formatted bundles, only ESM formatted ones.
In your populate.ts script you will need to access the @angular/core via an ESM import. I suspect that ts-node is outputting CommonJS, which will convert import statements to require() calls. You cannot use require() to import ESM modules.
Given that you are running node v16, you should be able to target ESM modules in your tsconfig.json natively. Try changing "module": "commonjs", to "module": "ES2020",.
Alternatively you could switch to using async import expressions to load in the Angular code.
Which @angular/* package(s) are the source of the bug?
core
Is this a regression?
Yes
Description
In our project, we have some angular services (that have a @Injectable({ providedIn: 'root' }) and an import { Injectable } from '@angular/core';)
During our CI process we re-use these services outside of our angular application to dynamically populate our test database.
We do this through calling these services in a ts-node script.
When upgrading to angular 13, when we do "ts-node populate.ts" we get:
Is this expected?
Do we need to change something to the tsconfig.json file (see below) with which we call the ts-node script?
{ "compilerOptions": { "lib": ["esnext", "dom"], "types": [], "module": "commonjs", "noImplicitReturns": true, "esModuleInterop": true, "allowSyntheticDefaultImports": true, "outDir": "lib", "sourceMap": true, "target": "es2017" }, "compileOnSave": true, "include": ["src"] }Please provide a link to a minimal reproduction of the bug
No response
Please provide the exception or error you saw
No response
Please provide the environment you discovered this bug in
Anything else?
No response
The text was updated successfully, but these errors were encountered: