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

后端 未结 11 635
遥遥无期
遥遥无期 2020-12-09 07:40

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 bel

相关标签:
11条回答
  • 2020-12-09 07:46

    I was able to solve this problem by removing node_modules then running "npm install"

    0 讨论(0)
  • 2020-12-09 07:51

    If you don't have particular needs, I suggest to install Typescript locally.

    NPM Installation Method

    npm install --global typescript # Global installation
    npm install --save-dev typescript # Local installation
    

    Yarn Installation Method

    yarn global add typescript # Global installation
    yarn add --dev typescript # Local installation
    
    0 讨论(0)
  • 2020-12-09 07:56

    This should do the trick,

    npm install -g typescript
    
    0 讨论(0)
  • 2020-12-09 08:00

    I had a similar problem when I rearranged the folder structure of a project. I tried all the hints given in this thread but none of them worked. After checking further I discovered that I forgot to copy an important hidden file over to the new directory. That was

    .angular-cli.json

    from the root directory of the @angular/cli project. After I copied that file over all was running as expected.

    0 讨论(0)
  • 2020-12-09 08:00

    Run: npm link typescript if you installed globally

    But if you have not installed typescript try this command: npm install typescript

    0 讨论(0)
  • 2020-12-09 08:03

    I had the same problem. If you have installed first nodejs by apt and then you use the tar.gz from nodejs.org, you have to delete the folder located in /usr/lib/node_modules.

    0 讨论(0)
提交回复
热议问题