Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix Cannot find module 'typescript' in Angular 4?

I generated Angular 4 app 3 weeks ago using the @angular/cli. After 2 weeks, I tried to run it with the command line ng serve but I am prompted an error below:

Cannot find module 'typescript' Error: Cannot find module 'typescript'     at Function.Module._resolveFilename (module.js:469:15)     at Function.Module._load (module.js:417:25)     at Module.require (module.js:497:17)     at require (internal/module.js:20:19)     at Object.<anonymous> (C:\Users\mypc\Documents\Angular Projects\my-angular-app\node_modules\@angular\cli\models\config\config.js:5:12)     at Module._compile (module.js:570:32)     at Object.Module._extensions..js (module.js:579:10)     at Module.load (module.js:487:32)     at tryModuleLoad (module.js:446:12)     at Function.Module._load (module.js:438:3) 

Do you have any idea how to fix this? Thanks.

like image 303
redshot Avatar asked Jun 18 '17 03:06

redshot


People also ask

Can not find module in angular?

To solve the error "Cannot find module '@angular/core'", make sure you have installed all dependencies by running the npm install command, set the baseUrl option to src in your tsconfig. json file and restart your IDE and development server.

Can not find module TS?

The "Cannot find module or its corresponding type declarations" error occurs when TypeScript cannot locate a third-party or local module in our project. To solve the error, make sure to install the module and try setting moduleResolution to node in your tsconfig. json file.

How do I install TypeScript globally?

You can use npm to install TypeScript globally, this means that you can use the tsc command anywhere in your terminal. To do this, run npm install -g typescript . This will install the latest version (currently 4.7).

How do I find the TypeScript version?

Test that the TypeScript is installed correctly by typing tsc -v into your terminal or command prompt. You should see the TypeScript version print out to the screen. For help on possible arguments you can type tsc -h or just tsc .


1 Answers

For me just running the below command is not enough (though a valid first step):

npm install -g typescript 

The following command is what you need (I think deleting node_modules works too, but the below command is quicker)

npm link typescript 
like image 131
DanAbdn Avatar answered Sep 24 '22 08:09

DanAbdn