【问题标题】:Node_modules folder is empty after npm install commandnpm install 命令后 Node_modules 文件夹为空
【发布时间】:2019-02-07 21:27:59
【问题描述】:

我正在关注一个 Angular 项目,该项目的开始发布在 https://github.com/pluralsight-projects/Angular-AlbumStoreProductPage

我分叉了这个并在我的本地机器(操作系统 windows 10)上进行了克隆。

指南告诉我在 package.json 文件所在的根文件夹中运行以下命令:

  • npm 安装
  • npm install -g @angular/cli@1.6.5
  • npm 运行测试

执行最后一条命令时,我收到错误

'mocha' is not recognized as an internal or external command,
operable program or batch file.
node_modules appears empty, you may need to run `npm install`

我的 node_modules 文件夹确实是空的,我真的不知道为什么 'npm install' 没有添加这个文件夹。是的,在问这个之前我先用谷歌搜索。 :)

请参阅下面我运行以下命令的命令提示符:

  1. dir(显示我的项目根文件夹的文件夹,没有node_modules文件夹)
  2. 输入 package.json(仅供参考,我的 package.json 文件的内容)
  3. npm install(这里没有收到任何输出..)
  4. npm install -g @angular/cli@1.6.5
  5. npm run test(仅供参考,它失败了)
  6. dir(仅供参考,在安装 cmd 后显示我的文件夹中的目录,没有 node_modules 文件夹)

命令:

Microsoft Windows [Version 10.0.16299.547]
(c) 2017 Microsoft Corporation. All rights reserved.

C:\Users\kderous>d:

D:\>cd dev\angular\angular-albumstoreproductpage

D:\dev\Angular\Angular-AlbumStoreProductPage>dir
 Volume in drive D is Data
 Volume Serial Number is 3295-A0CE

 Directory of D:\dev\Angular\Angular-AlbumStoreProductPage

02/09/2018  17:30    <DIR>          .
02/09/2018  17:30    <DIR>          ..
02/09/2018  17:26             1.247 .angular-cli.json
02/09/2018  17:26               258 .editorconfig
02/09/2018  17:26               619 .gitignore
02/09/2018  17:26                15 .npmrc
02/09/2018  17:26                 7 .nvmrc
02/09/2018  17:35               961 3.0
02/09/2018  17:35                 0 cd
02/09/2018  18:38                 0 dir
02/09/2018  17:26    <DIR>          e2e
02/09/2018  17:26             1.677 karma.conf.js
02/09/2018  17:35                 0 npm
02/09/2018  17:26           517.785 package-lock.json
02/09/2018  17:26             4.076 package.json
02/09/2018  17:26               786 protractor.conf.js
02/09/2018  17:26             1.520 README.md
02/09/2018  17:26    <DIR>          src
02/09/2018  17:26               405 tsconfig.json
02/09/2018  17:26             2.826 tslint.json
02/09/2018  17:35                 0 type
02/09/2018  17:30                 0 Your
              18 File(s)        532.182 bytes
               4 Dir(s)  406.178.123.776 bytes free

D:\dev\Angular\Angular-AlbumStoreProductPage>type package.json
{
  "name": "pluralsight-project-build-an-album-store-product-page-with-angular",
  "version": "0.0.2",
  "license": "MIT",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "./node_modules/.bin/mocha ./src/spec/mocha-specs --recursive --reporter spec & ng test --single-run",
    "test:part2": "./node_modules/.bin/mocha ./src/spec/mocha-specs/part2/ --recursive --reporter spec & ng test --single-run --part part2",
    "test:part3": "./node_modules/.bin/mocha ./src/spec/mocha-specs/part3/ --recursive --reporter spec & ng test --single-run --part part3",
    "test:part4": "./node_modules/.bin/mocha ./src/spec/mocha-specs/part4/ --recursive --reporter spec & ng test --single-run --part part4",
    "test:part5": "./node_modules/.bin/mocha ./src/spec/mocha-specs/part5/ --recursive --reporter spec & ng test --single-run --part part5",
    "test:part6": "./node_modules/.bin/mocha ./src/spec/mocha-specs/part6/ --recursive --reporter spec & ng test --single-run --part part6",
    "test:part7": "./node_modules/.bin/mocha ./src/spec/mocha-specs/part7/ --recursive --reporter spec & ng test --single-run --part part7",
    "tutor-test": "./node_modules/.bin/mocha ./src/spec/mocha-specs --recursive --reporter json & ng test --config tutor-karma.conf.js --single-run",
    "tutor-test:part2": "./node_modules/.bin/mocha ./src/spec/mocha-specs/part2/ --recursive --reporter json & ng test --config tutor-karma.conf.js --single-run --part part2",
    "tutor-test:part3": "./node_modules/.bin/mocha ./src/spec/mocha-specs/part3/ --recursive --reporter json & ng test --config tutor-karma.conf.js --single-run --part part3",
    "tutor-test:part4": "./node_modules/.bin/mocha ./src/spec/mocha-specs/part4/ --recursive --reporter json & ng test --config tutor-karma.conf.js --single-run --part part4",
    "tutor-test:part5": "./node_modules/.bin/mocha ./src/spec/mocha-specs/part5/ --recursive --reporter json & ng test --config tutor-karma.conf.js --single-run --part part5",
    "tutor-test:part6": "./node_modules/.bin/mocha ./src/spec/mocha-specs/part6/ --recursive --reporter json & ng test --config tutor-karma.conf.js --single-run --part part6",
    "tutor-test:part7": "./node_modules/.bin/mocha ./src/spec/mocha-specs/part7/ --recursive --reporter json & ng test --config tutor-karma.conf.js --single-run --part part7",
    "mocha-spec": "./node_modules/.bin/mocha ./src/spec/mocha-specs/ --reporter spec",
    "mocha-json": "./node_modules/.bin/mocha ./src/spec/mocha-specs/ --reporter json",
    "karma-spec": "ng test --config tutor-karma.conf.js --single-run",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "5.2.0",
    "@angular/common": "5.2.0",
    "@angular/compiler": "5.2.0",
    "@angular/core": "5.2.0",
    "@angular/forms": "5.2.0",
    "@angular/http": "5.2.0",
    "@angular/platform-browser": "5.2.0",
    "@angular/platform-browser-dynamic": "5.2.0",
    "@angular/router": "5.2.0",
    "core-js": "2.4.1",
    "rxjs": "5.5.6",
    "zone.js": "0.8.12"
  },
  "devDependencies": {
    "@angular/cli": "1.6.5",
    "@angular/compiler-cli": "5.2.0",
    "@angular/language-service": "5.2.0",
    "@types/jasmine": "2.8.3",
    "@types/jasminewd2": "2.0.2",
    "@types/node": "6.0.60",
    "bootstrap": "3.3.7",
    "chai": "4.0.1",
    "codelyzer": "4.0.1",
    "cssom": "0.3.0",
    "jasmine-core": "2.8.0",
    "jasmine-spec-reporter": "4.2.1",
    "jasmine2-custom-message": "0.8.2",
    "karma": "2.0.0",
    "karma-chrome-launcher": "2.2.0",
    "karma-cli": "1.0.1",
    "karma-coverage-istanbul-reporter": "1.2.1",
    "karma-jasmine": "1.1.0",
    "karma-jasmine-html-reporter": "0.2.2",
    "karma-nightmare": "0.4.13",
    "karma-spec-reporter": "0.0.31",
    "karma-structured-json-reporter": "1.0.0",
    "minimist": "1.2.0",
    "mocha": "3.4.2",
    "protractor": "5.1.2",
    "ts-node": "4.1.0",
    "tslint": "5.9.1",
    "typescript": "2.5.3"
  }
}

D:\dev\Angular\Angular-AlbumStoreProductPage>npm install

D:\dev\Angular\Angular-AlbumStoreProductPage>npm install -g @angular/cli@1.6.5
npm WARN deprecated browserslist@2.11.3: Browserslist 2 could fail on reading Browserslist >3.0 config used in other tools.
npm WARN deprecated browserslist@1.7.7: Browserslist 2 could fail on reading Browserslist >3.0 config used in other tools.
C:\Users\kderous\AppData\Roaming\npm\ng -> C:\Users\kderous\AppData\Roaming\npm\node_modules\@angular\cli\bin\ng
npm WARN ajv-keywords@3.2.0 requires a peer of ajv@^6.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.4 (node_modules\@angular\cli\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.4: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})

+ @angular/cli@1.6.5
updated 1 package in 57.762s

D:\dev\Angular\Angular-AlbumStoreProductPage>npm run test
'mocha' is not recognized as an internal or external command,
operable program or batch file.
node_modules appears empty, you may need to run `npm install`

D:\dev\Angular\Angular-AlbumStoreProductPage>dir
 Volume in drive D is Data
 Volume Serial Number is 3295-A0CE

 Directory of D:\dev\Angular\Angular-AlbumStoreProductPage

02/09/2018  17:30    <DIR>          .
02/09/2018  17:30    <DIR>          ..
02/09/2018  17:26             1.247 .angular-cli.json
02/09/2018  17:26               258 .editorconfig
02/09/2018  17:26               619 .gitignore
02/09/2018  17:26                15 .npmrc
02/09/2018  17:26                 7 .nvmrc
02/09/2018  17:35               961 3.0
02/09/2018  17:35                 0 cd
02/09/2018  18:38                 0 dir
02/09/2018  17:26    <DIR>          e2e
02/09/2018  17:26             1.677 karma.conf.js
02/09/2018  17:35                 0 npm
02/09/2018  17:26           517.785 package-lock.json
02/09/2018  17:26             4.076 package.json
02/09/2018  17:26               786 protractor.conf.js
02/09/2018  17:26             1.520 README.md
02/09/2018  17:26    <DIR>          src
02/09/2018  17:26               405 tsconfig.json
02/09/2018  17:26             2.826 tslint.json
02/09/2018  17:35                 0 type
02/09/2018  17:30                 0 Your
              18 File(s)        532.182 bytes
               4 Dir(s)  406.178.123.776 bytes free

D:\dev\Angular\Angular-AlbumStoreProductPage>

如果你有什么建议,请告诉我。

提前致谢!

【问题讨论】:

    标签: node.js angular npm angular-cli


    【解决方案1】:

    我自己找到了答案。

    在我的项目中,我似乎有一个 .npmrc 文件。 这将禁用“npm install”命令的日志记录。

    临时删除后,我执行 npm install 并收到以下错误:

    npm ERR! code ENOGIT
    npm ERR! No git binary found in $PATH
    npm ERR!
    npm ERR! Failed using git.
    npm ERR! Please check if you have git installed and in your PATH.
    
    npm ERR! A complete log of this run can be found in:
    npm ERR!     C:\Users\kderous\AppData\Roaming\npm-cache\_logs\2018-09-02T17_38_45_205Z-debug.log
    

    我的问题是我没有在本地机器上安装 git。 安装 git 后,我​​的 npm_install 命令工作正常。

    【讨论】:

      【解决方案2】:

      在 package.json 中添加 "test": "nodemon --exec \"mocha -R min\""

      【讨论】:

        【解决方案3】:

        您应该尝试在运行npm install 之后运行npm install -g @angular/cli@1.6.5

        【讨论】:

          【解决方案4】:

          在我的例子中,将虚拟内存大小增加到 16gb(在 Windows 上)解决了这个问题。

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 2021-11-09
            • 2016-10-29
            • 2022-01-15
            • 2016-11-23
            • 2019-01-13
            • 1970-01-01
            • 2021-12-06
            • 2021-01-30
            相关资源
            最近更新 更多