node.js 什么可能导致与 npm 无法找到文件相关的错误?我的 node_modules 子文件夹中没有内容。这是为什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/49415958/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 18:44:27  来源:igfitidea点击:

What could cause an error related to npm not being able to find a file? No contents in my node_modules subfolder. Why is that?

node.jsangularnpmnode-modulesaspnetboilerplate

提问by jlavallet

I'm trying to run npm installin the angular project folder I got from ASP.NET Boilerplateand I'm getting an error that is "related to npm not being able to find a file."

我正在尝试npm install在从ASP.NET Boilerplate获得的 angular 项目文件夹中运行,但出现“与 npm 无法找到文件有关”的错误。

D:\Dev\AspNetBoilerplate\MyProject.5.0\angular>npm install
npm WARN deprecated @types/[email protected]: This is a stub types definition for Moment (https://github.com/moment/moment). Moment provides its own type definitions, so you don't need @types/moment installed!
npm WARN [email protected] requires a peer of @angular/compiler@^2.3.1 || >=4.0.0-beta <5.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of @angular/core@^2.3.1 || >=4.0.0-beta <5.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules\fsevents):
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: Error: EPERM: operation not permitted, rename 'D:\Dev\AspNetBoilerplate\MyProject.5.0\angular\node_modules\.staging\fsevents-8cc0601e\node_modules\are-we-there-yet' -> 'D:\Dev\AspNetBoilerplate\MyProject.5.0\angular\node_modules\.staging\are-we-there-yet-cedb4a6a'

npm ERR! path D:\Dev\AspNetBoilerplate\MyProject.5.0\angular\node_modules\@angular-devkit\build-optimizer\node_modules\typescript
npm ERR! code ENOENT
npm ERR! errno -4058
npm ERR! syscall rename
npm ERR! enoent ENOENT: no such file or directory, rename 'D:\Dev\AspNetBoilerplate\MyProject.5.0\angular\node_modules\@angular-devkit\build-optimizer\node_modules\typescript' -> 'D:\Dev\AspNetBoilerplate\MyProject.5.0\angular\node_modules\@angular-devkit\build-optimizer\node_modules\.typescript.DELETE'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Hyman\AppData\Roaming\npm-cache\_logs18-03-21T19_33_18_250Z-debug.log

I can clearly see that this is happening because my node_modulessubfolder contains only a single folder structure with no files within it. That structure is:

我可以清楚地看到这是因为我的node_modules子文件夹只包含一个文件夹结构,其中没有文件。该结构是:

node_modules\@angular-devkit\build-optimizer\node_modules

I have node 8.9.4, npm 5.6.0, and angular-cli 1.5.0 installed as well as typescript 2.0.0. The latter two packages have been installed globally.

我安装了 node 8.9.4、npm 5.6.0 和 angular-cli 1.5.0 以及 typescript 2.0.0。后两个包已经全局安装。

Here is the package.jsonfile contents:

这是package.json文件内容:

{
    "name": "MyProject",
    "version": "0.0.0",
    "license": "MIT",
    "angular-cli": {},
    "scripts": {
        "ng": "ng",
        "start": "ng serve --host 0.0.0.0 --port 4200",
        "hmr": "ng serve --host 0.0.0.0 --port 4200 4201 --hmr -e=hmr",
        "test": "ng test",
        "pree2e": "webdriver-manager update --standalone false --gecko false",
        "e2e": "protractor"
    },
    "private": true,
    "dependencies": {
        "@angular/animations": "^5.0.3",
        "@angular/common": "^5.0.3",
        "@angular/compiler": "^5.0.3",
        "@angular/core": "^5.0.3",
        "@angular/forms": "^5.0.3",
        "@angular/http": "^5.0.3",
        "@angular/platform-browser": "^5.0.3",
        "@angular/platform-browser-dynamic": "^5.0.3",
        "@angular/router": "^5.0.3",
        "@aspnet/signalr": "1.0.0-preview1-28189",
        "@types/bootstrap": "^3.3.33",
        "@types/jquery": "^3.2.12",
        "@types/jquery.blockui": "0.0.28",
        "@types/jquery.validation": "^1.16.3",
        "@types/lodash": "^4.14.62",
        "@types/moment": "^2.13.0",
        "@types/moment-timezone": "^0.2.34",
        "@types/signalr": "^2.2.33",
        "@types/toastr": "^2.1.33",
        "abp-ng2-module": "^1.3.0",
        "abp-web-resources": "^3.3.0",
        "animate.css": "^3.5.2",
        "block-ui": "^2.70.1",
        "bootstrap": "^3.3.7",
        "bootstrap-select": "^1.12.2",
        "chart.js": "^2.6.0",
        "core-js": "^2.4.1",
        "famfamfam-flags": "^1.0.0",
        "flot": "^0.8.0-alpha",
        "font-awesome": "^4.7.0",
        "jquery": "^3.1.1",
        "jquery-countto": "^1.2.0",
        "jquery-migrate": "^3.0.0",
        "jquery-slimscroll": "^1.3.8",
        "jquery-sparkline": "^2.4.0",
        "js-cookie": "^2.1.4",
        "lodash": "^4.17.4",
        "moment": "^2.18.1",
        "moment-timezone": "^0.5.13",
        "morris.js": "^0.5.0",
        "ngx-bootstrap": "^2.0.2",
        "ngx-pagination": "^3.0.3",
        "node-waves": "^0.7.5",
        "push.js": "1.0.4",
        "raphael": "^2.2.7",
        "rxjs": "^5.5.2",
        "signalr": "^2.2.1",
        "simple-line-icons": "^2.4.1",
        "spin.js": "^2.3.2",
        "sweetalert": "^2.0.8",
        "toastr": "^2.1.2",
        "ts-helpers": "^1.1.2",
        "web-animations-js": "^2.3.1",
        "zone.js": "0.8.18"
    },
    "devDependencies": {
        "@angular/cli": "^1.5.4",
        "@angular/compiler-cli": "^5.0.3",
        "@angularclass/hmr": "^2.1.3",
        "@types/jasmine": "^2.5.38",
        "@types/node": "^8.0.27",
        "codelyzer": "^3.1.2",
        "jasmine-core": "^2.5.2",
        "jasmine-spec-reporter": "^4.2.1",
        "karma": "^1.4.1",
        "karma-chrome-launcher": "^2.0.0",
        "karma-cli": "^1.0.1",
        "karma-coverage-istanbul-reporter": "^1.3.0",
        "karma-jasmine": "^1.1.0",
        "karma-jasmine-html-reporter": "^0.2.2",
        "nswag": "^11.12.7",
        "protractor": "^5.1.1",
        "ts-node": "^3.3.0",
        "tslint": "^5.7.0",
        "typescript": "2.4.2"
    }
}

When I run npm install, I can see the packages being downloaded into the .stagingfolder. At the point that the finalizecommand is run (see the log below), I can see that the package folders are being consolidated and copied somewhere, but that somewhere does not appear to be my node_modulessubfolder other than the first set of subfolders as I have shown above. When the npm installcompletes, the .stagingfolder is deleted and all that I have left is that partial folder structure.

当我运行时npm install,我可以看到正在下载到.staging文件夹中的包。在finalize运行命令时(请参阅下面的日志),我可以看到包文件夹正在合并并复制到某处,但node_modules除了第一组子文件夹之外,该处似乎不是我的子文件夹,如我所示以上。当npm install完成时,.staging删除文件夹和所有我已经离开的是,部分文件夹结构。

Admittedly I am new to Node development - I usually work on our ASP.NET Web API backends. I'm trying to get my development environment in sync with our front end developer's development environment. I have spent most of the day looking for a solution. I've tried uninstalling and reinstalling Node. I've tried different versions that match our front end developer's environment. I've tried using the latest versions of angular-cli and typescript and have fallen back to the versions I reference above in hopes that the "requires a peer" warnings would be resolved. I have searched for similar answers on this site. The closest one I have foundremains unanswered.

诚然,我是 Node 开发的新手 - 我通常在我们的 ASP.NET Web API 后端工作。我试图让我的开发环境与我们前端开发人员的开发环境同步。我花了一天的大部分时间寻找解决方案。我试过卸载并重新安装 Node.js。我尝试了与我们的前端开发人员环境相匹配的不同版本。我已经尝试使用最新版本的 angular-cli 和 typescript 并回退到我上面引用的版本,希望“需要对等”警告得到解决。我在这个网站上搜索过类似的答案。我找到的最接近的一个仍未得到答复。

Here is the end of the "complete log" referenced in the npm error output:

这是 npm 错误输出中引用的“完整日志”的结尾:

19577 silly saveTree | `-- [email protected]
19577 silly saveTree +-- [email protected]
19577 silly saveTree +-- [email protected]
19577 silly saveTree `-- [email protected]
19578 warn [email protected] requires a peer of @angular/compiler@^2.3.1 || >=4.0.0-beta <5.0.0 but none is installed. You must install peer dependencies yourself.
19579 warn [email protected] requires a peer of @angular/core@^2.3.1 || >=4.0.0-beta <5.0.0 but none is installed. You must install peer dependencies yourself.
19580 warn optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules\fsevents):
19581 warn optional SKIPPING OPTIONAL DEPENDENCY: Error: EPERM: operation not permitted, rename 'D:\Dev\AspNetBoilerplate\MyProject.5.0\angular\node_modules\.staging\fsevents-8cc0601e\node_modules\are-we-there-yet' -> 'D:\Dev\AspNetBoilerplate\MyProject.5.0\angular\node_modules\.staging\are-we-there-yet-cedb4a6a'
19582 verbose optional SKIPPING OPTIONAL DEPENDENCY:
19582 verbose optional Please try running this command again as root/Administrator.
19583 verbose stack Error: ENOENT: no such file or directory, rename 'D:\Dev\AspNetBoilerplate\MyProject.5.0\angular\node_modules\@angular-devkit\build-optimizer\node_modules\typescript' -> 'D:\Dev\AspNetBoilerplate\MyProject.5.0\angular\node_modules\@angular-devkit\build-optimizer\node_modules\.typescript.DELETE'
19584 verbose cwd D:\Dev\AspNetBoilerplate\MyProject.5.0\angular
19585 verbose Windows_NT 10.0.16299
19586 verbose argv "C:\Program Files\nodejs\node.exe" "C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js" "install"
19587 verbose node v8.9.4
19588 verbose npm  v5.6.0
19589 error path D:\Dev\AspNetBoilerplate\MyProject.5.0\angular\node_modules\@angular-devkit\build-optimizer\node_modules\typescript
19590 error code ENOENT
19591 error errno -4058
19592 error syscall rename
19593 error enoent ENOENT: no such file or directory, rename 'D:\Dev\AspNetBoilerplate\MyProject.5.0\angular\node_modules\@angular-devkit\build-optimizer\node_modules\typescript' -> 'D:\Dev\AspNetBoilerplate\MyProject.5.0\angular\node_modules\@angular-devkit\build-optimizer\node_modules\.typescript.DELETE'
19594 error enoent This is related to npm not being able to find a file.
19595 verbose exit [ -4058, true ]

Please advise.

请指教。

采纳答案by vivek nuna

It might be related to corruption in Angular Packages or incompatibility of packages.

这可能与 Angular 包中的损坏或包的不兼容有关。

Please follow the below steps to solve the issue.

请按照以下步骤解决问题。

Update

更新

ASP.NET Boilerplate suggests hereto use yarn because npm has some problems. It is slow and can not consistently resolve dependencies, yarn solves those problems and it is compatible to npm as well.

ASP.NET Boilerplate 建议这里使用 yarn 因为 npm 有一些问题。它很慢并且不能始终如一地解决依赖关系,yarn 解决了这些问题并且它也与 npm 兼容。

回答by binaryDi

The following steps work for me:

以下步骤对我有用:

  1. npm cache clean -f
  2. rm -rf node_modules
  3. npm i
  1. npm cache clean -f
  2. rm -rf node_modules
  3. npm i

回答by jlavallet

Following what @viveknuna suggested, I upgraded to the latest version of node.js and npm using the downloaded installer. I also installed the latest version of yarn using a downloaded installer. Then, as you can see below, I upgraded angular-cli and typescript. Here's what that process looked like:

按照@viveknuna 的建议,我使用下载的安装程序升级到最新版本的 node.js 和 npm。我还使用下载的安装程序安装了最新版本的纱线。然后,如下所示,我升级了 angular-cli 和 typescript。这是这个过程的样子:

D:\Dev\AspNetBoilerplate\MyProject.5.0\angular>npm install -g @angular/cli@latest
C:\Users\Hyman\AppData\Roaming\npm\ng -> C:\Users\Hyman\AppData\Roaming\npm\node_modules\@angular\cli\bin\ng
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules\@angular\cli\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})

+ @angular/[email protected]
added 75 packages, removed 166 packages, updated 61 packages and moved 24 packages in 29.084s

D:\Dev\AspNetBoilerplate\MyProject.5.0\angular>npm install -g typescript
C:\Users\Hyman\AppData\Roaming\npm\tsserver -> C:\Users\Hyman\AppData\Roaming\npm\node_modules\typescript\bin\tsserver
C:\Users\Hyman\AppData\Roaming\npm\tsc -> C:\Users\Hyman\AppData\Roaming\npm\node_modules\typescript\bin\tsc
+ [email protected]
updated 1 package in 2.427s

D:\Dev\AspNetBoilerplate\MyProject.5.0\angular>node -v
v8.10.0

D:\Dev\AspNetBoilerplate\MyProject.5.0\angular>npm -v
5.6.0

D:\Dev\AspNetBoilerplate\MyProject.5.0\angular>yarn --version
1.5.1

Thereafter, I ran yarnand npm startin my angular folder and all appears to be well. Here's what that looked like:

此后,我跑yarn,并npm start在我的角度文件夹和所有似乎很好。这是它的样子:

D:\Dev\AspNetBoilerplate\MyProject.5.0\angular>yarn
yarn install v1.5.1
[1/4] Resolving packages...
[2/4] Fetching packages...
info [email protected]: The platform "win32" is incompatible with this module.
info "[email protected]" is an optional dependency and failed compatibility check. Excluding it from installation.
[3/4] Linking dependencies...
warning "@angular/cli > @schematics/[email protected]" has incorrect peer dependency "@angular-devkit/[email protected]".
warning "@angular/cli > @angular-devkit/schematics > @schematics/[email protected]" has incorrect peer dependency "@angular-devkit/[email protected]".
warning " > [email protected]" has incorrect peer dependency "@angular/compiler@^2.3.1 || >=4.0.0-beta <5.0.0".
warning " > [email protected]" has incorrect peer dependency "@angular/core@^2.3.1 || >=4.0.0-beta <5.0.0".
[4/4] Building fresh packages...
Done in 232.79s.

D:\Dev\AspNetBoilerplate\MyProject.5.0\angular>npm start

> [email protected] start D:\Dev\AspNetBoilerplate\MyProject.5.0\angular
> ng serve --host 0.0.0.0 --port 4200

** NG Live Development Server is listening on 0.0.0.0:4200, open your browser on http://localhost:4200/ **
Date: 2018-03-22T13:17:28.935Z
Hash: 8f226b6fa069b7c201ea
Time: 22494ms
chunk {account.module} account.module.chunk.js () 129 kB  [rendered]
chunk {app.module} app.module.chunk.js () 497 kB  [rendered]
chunk {common} common.chunk.js (common) 1.46 MB  [rendered]
chunk {inline} inline.bundle.js (inline) 5.79 kB [entry] [rendered]
chunk {main} main.bundle.js (main) 515 kB [initial] [rendered]
chunk {polyfills} polyfills.bundle.js (polyfills) 1.1 MB [initial] [rendered]
chunk {styles} styles.bundle.js (styles) 1.53 MB [initial] [rendered]
chunk {vendor} vendor.bundle.js (vendor) 15.1 MB [initial] [rendered]

webpack: Compiled successfully.

回答by jokerster

Try the following steps:
1. Make sure you have the latest npm (npm install -g npm).
2. Add an exception to your antivirus to ignore the node_modules folder in your project.
3. $ rm -rf node_modules package-lock.json .
4. $ npm install

尝试以下步骤:
1. 确保您拥有最新的 npm (npm install -g npm)。
2. 为您的防病毒软件添加一个例外,以忽略您项目中的 node_modules 文件夹。
3. $ rm -rf node_modules package-lock.json 。
4. $ npm 安装

回答by Alexander Napoles

I had the SAME issue today and it was driving me nuts!!! What I had done was upgrade to node 8.10 and upgrade my NPM to the latest I uninstalled angular CLI

我今天遇到了同样的问题,这让我发疯了!!!我所做的是升级到节点 8.10 并将我的 NPM 升级到最新的我卸载了 angular CLI

npm uninstall -g angular-cli
npm uninstall --save-dev angular-cli

I then verified my Cache from NPM if it wasn't up to date I cleaned it and ran the install again if npm version is < 5 then use npm cache clean --force

然后我从 NPM 验证我的缓存,如果它不是最新的我清理它并再次运行安装,如果 npm 版本 < 5 然后使用 npm cache clean --force

npm install -g @angular/cli@latest

and created a new project file and create a new angular project.

并创建了一个新的项目文件并创建了一个新的 angular 项目。

回答by Elvis Moraes

In my case, this error happened with a new project.

就我而言,这个错误发生在一个新项目中。

none of the proposed solutions here worked, so I simply reinstalled all the packages and started working correctly.

这里提出的解决方案都没有奏效,所以我只是重新安装了所有软件包并开始正常工作。