Reputation: 16266
I have an angular 8, that uses karma/jasmine to run some unit tests. I can run tests by executing the following command ng test
but I'm getting the following error:
ERROR in ./src/polyfills.ts Module not found: Error: Can't resolve 'zone.js/dist/zone' in 'C:\PrjNET\Elevation3\FW\4.00\Project\Framework\Development\Client\ElevationJS\shell\src' resolve 'zone.js/dist/zone' in 'C:\PrjNET\Elevation3\FW\4.00\Project\Framework\Development\Client\ElevationJS\shell\src'
Any one know how to solve it?
Upvotes: 11
Views: 31727
Reputation: 467
In my case I was migrating from Angular 7 to Angular 18 and I had this problems. So to solve I went fo polyfills.ts
file and I changed : import 'zone.js/dist/zone'
to import 'zone.js'
Upvotes: 0
Reputation: 182
Basically there is an issue with imports.So I looked for reflect folder inside node_modules/core-js and I copy pasted same path in polyfills.js. It worked.
from
import "core-js/es/reflect";
import "core-js/es7/reflect";
to
import "core-js/es/reflect";
Upvotes: 1
Reputation: 1781
Change
zone.js/dist/zone
to
zone.js
As for me, updating the version did NOT work.
I checked the project created with "ng new project", and in the "polyfills.ts" file, it was "zone.js" instead of "zone.js/dist/zone".
So I changed it to "zone.js", and it started to work.
Upvotes: 11
Reputation: 6136
zone-testing
only exists from 0.8.19
. Try to install the latest version. using:
npm i zone.js
above command worked in my case.
Upvotes: 8
Reputation: 29689
I fixed it in my project with this command:
npm install [email protected] --save
I was getting this error using [email protected]
.
Upvotes: 24
Reputation: 16266
I found out that my test configurations on tsconfig.spec.json
were wrong. So I change from this:
{
"extends": "./tsconfig.es5.json",
"compilerOptions": {
"outDir": "../out-tsc/spec",
"module": "commonjs",
"target": "es6",
"baseUrl": "",
"types": [
"jest",
"node"
]
},
"files": [
"test.ts",
"polyfills.ts"
],
"include": [
"**/*.spec.ts",
"**/*.d.ts"
]
}
to this:
{
"extends": "./tsconfig.es5.json",
"compilerOptions": {
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"outDir": "../out-tsc/spec",
"module": "commonjs",
"types": [
"jasmine",
"node"
]
},
"files": [
"test.ts",
"polyfills.ts"
],
"include": [
"**/*.spec.ts",
"**/*.d.ts"
]
}
And the error disapeared!
Upvotes: 4