Reputation: 21
When running ng serve my code fails to compile and gives me this error:
ERROR in node_modules/@angular/compiler-cli/src/transformers/program.d.ts(9,23): error TS2307: Cannot find module 'path'.
I thought that it had something to do with that my local angular version is an older version than my global version, so I tried this solution
But this didn't help. Now for my code to compile I have to delete a ';' somewhere random in my project, save the project, add the semicolon back and save the project. With this method, my code compiles and my app works but the error is still there.
Upvotes: 2
Views: 3483
Reputation: 156
Had this issue as well. Here's my solution in case anybody stumbles upon this as well without being able to resolve it based on the majority of the proposed online solutions (to be precise: the majority of the proposed solutions i found, contained fixing a 'typo' or removing an import, none of which resolved my case):
I was on Angular 9.1 when this issue occured (i do not remember what caused it to occur in the first place), updating to angular 10.0 and updating all my packages didn't resolve the issue.
In the end, i had to add "node" to the "type" attribute: file: src/tsconfig.app.json
{
"extends": "../tsconfig.json",
"compilerOptions": {
"outDir": "../out-tsc/app",
"types": ["node"] <======== added "node" here
},
"files": [
"main.ts",
"polyfills.ts"
],
"include": [
"src/**/*.d.ts"
]
}
This file extends the regular tsconfig.json file. You could also add the "types" attribute under compilerOptions to the parent file, but it's better to add the "node" element in the "types" array of the application tsconfig.
Upvotes: 3
Reputation: 709
After reading this (https://github.com/angular/angular-cli/issues/9151) I realized that I had somewhere a wrong import statement in my .ts file:
import {Definition} from "@angular/compiler-cli";
but it should be:
import {Definition} from "path/in/my/src/folder";
I suggest to search in workspace for: "@angular/compiler-cli" and check if it is correct on this place.
Upvotes: 5