简体   繁体   English

全局安装npm,仍然为每个Angular项目安装它给我错误,再次安装

[英]Installed npm globally, still for each Angular Project It is giving me ERROR to install it again

I have recently started learning Angular 4. So as mentioned in a tutorial I have installed nodejs, then angular 4 cli and create a project to start working. 我最近开始学习Angular4。因此,如本教程中所述,我已经安装了nodejs,然后安装了angular 4 cli,并创建了一个项目以开始工作。 I did the same and looks perfect but when I use ng serve --open to run local server. 我做了同样的事情,看起来很完美,但是当我使用ng serve --open运行本地服务器时。 It gives me following error: 它给了我以下错误:

角度服务-o错误

I have solved this issue with installing npm again in my angular app directory. 我已通过在我的角度应用程序目录中再次安装npm解决了此问题。

Now I am going to create a new app which is giving the same error and I don't want to install npm again and again for each project (the issue is also solved by copying node_modules folder from first app root to the new app) because I am in a learning phase so I am required to create a new project for each new thing I learn. 现在,我将创建一个给出相同错误的新应用,并且我不想为每个项目一次又一次地安装npm(此问题也可以通过将node_modules文件夹从第一个应用根目录复制到新应用中来解决)我处于学习阶段,因此必须为我学到的每一项新事物创建一个新项目。

Update: I am using Windows 8.1, latest version of Nodejs v8.1.4 (also tried the LTS), npm version 5.0.3 and Visual Studio Code. 更新:我正在使用Windows 8.1,最新版本的Nodejs v8.1.4(也尝试过LTS),npm版本5.0.3和Visual Studio Code。 Everything installs perfectly without any error. 一切都完美安装,没有任何错误。

Any new project created with @angular/cli doesn't ship node_modules out of the box. 使用@angular/cli创建的任何新项目都不会立即提供node_modules。 You got to run npm install in every single proejct you create. 您必须在创建的每个npm install中运行npm install (This is not the case with React CLI " create-react-app ".) The package json file is generated with every new project created. (React CLI“ create-react-app ”不是这种情况。)包json文件是随创建的每个新项目生成的。 So just run npm install in the root folder. 因此,只需在根文件夹中运行npm install

Dont copy the node_modules folder of any existing project. 不要复制任何现有项目的node_modules文件夹。 It may have dev/production dependencies that you may not need in your new project so why keep junk. 它可能具有在新项目中可能不需要的开发/生产依赖关系,所以为什么要保持垃圾状态。

The minimal package json created by CLI in your app folder has following scripts in place: 由CLI在您的应用文件夹中创建的最小软件包json具有以下脚本:

  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },

So if you do npm start or ng serve both will do the same. 因此,如果您执行npm startng serve两者都将执行相同的操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM