node.js `yo angular` 给出错误:npm ERR!代码 ENOENT npm ERR!errno 34(是的,我已经清理了缓存并设置了 .npmignore)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21964874/
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 16:55:12  来源:igfitidea点击:

`yo angular` gives error: npm ERR! code ENOENT npm ERR! errno 34 (yes I have cleaned the cache and set .npmignore)

node.jsangularjsnpmyeomanyeoman-generator

提问by randwa1k

I tried to run yo angularin a new project directory, but it gave me the ENOENT error somewhere along the way. Yes I have looked at this similar question, but its solution doesn't work for me.

我试图yo angular在一个新的项目目录中运行,但它在途中的某个地方给了我 ENOENT 错误。是的,我看过这个类似的问题,但它的解决方案对我不起作用。

I ran these things on the empty new project directory right before running yo angular:

我在运行之前在空的新项目目录上运行了这些东西yo angular

touch .npmignore
npm cache clear
npm cache clean

But I still get:

但我仍然得到:

npm ERR! Error: ENOENT, lstat '/home/ubuntu/app_c/node_modules/grunt/    internal-tasks/bump.js'
npm ERR! If you need help, you may report this *entire* log, 
npm ERR! including the npm and node versions, at:
npm ERR!     <http://github.com/npm/npm/issues>

npm ERR! System Linux 3.2.0-54-virtual
npm ERR! command "/home/ubuntu/local/bin/node" "/home/ubuntu/local/bin/  npm" "install"
npm ERR! cwd /home/ubuntu/app_c
npm ERR! node -v v0.10.26
npm ERR! npm -v 1.4.3
npm ERR! path /home/ubuntu/app_c/node_modules/grunt/internal-tasks/bump. js
npm ERR! fstream_path /home/ubuntu/app_c/node_modules/grunt/internal-    tasks/bump.js
npm ERR! fstream_type File 
npm ERR! fstream_class FileWriter
npm ERR! code ENOENT
npm ERR! errno 34
npm ERR! fstream_stack /home/ubuntu/local/lib/node_modules/npm/          node_modules/fstream/lib/writer.js:284:26
npm ERR! fstream_stack Object.oncomplete (fs.js:107:15)

How can I fix it?

我该如何解决?



Here is the history of ALL the commands, in chronological order, that I ranon a brand new Ubuntu Server 12.04.3, so you can see exactly what led up to this point, and where I have installed various packages.

这是我在全新的 Ubuntu Server 12.04.3 上运行的所有命令历史,按时间顺序排列,因此您可以确切地看到导致这一点的原因,以及我在何处安装了各种软件包。

This question is linked to an npm github issue.

这个问题链接到一个 npm github 问题

回答by JamesRLamar

EDIT: npm update -gfollowed by npm cache clearshould work for most. However, when first installing on Mac OS you may need to navigate to your usr/local/lib/node_modulesfolder once nodeJS is first installed and grant read/write permission to "Everyone". Node won't be able to installed additional workflow components globally until those permissions are released. You don't want to sudo the npm install commands, because then those tools won't have sudo access to run after the fact. Read/write permissions are changed by right-clicking the folder and going to "Get info" then changing permissions at bottom of popup.

编辑:npm update -g其次npm cache clear应该适用于大多数。但是,当第一次在 Mac OS 上安装时,您可能需要在usr/local/lib/node_modules第一次安装 nodeJS 后导航到您的文件夹并向“所有人”授予读/写权限。在这些权限被释放之前,Node 将无法全局安装其他工作流组件。您不想对 npm install 命令执行 sudo,因为这些工具将无法在事后运行 sudo 访问权限。通过右键单击文件夹并转到“获取信息”然后在弹出窗口底部更改权限来更改读/写权限。

I had this same issue on Windows 7 machine. Here are the steps I took to resolve:

我在 Windows 7 机器上遇到了同样的问题。以下是我解决的步骤:

  • repair Node installation
  • open elevated cli
  • run npm update -g
  • run npm cache clear
  • run npm install -g yo
  • run npm cache clear
  • run npm install -g generator-angular
  • run npm cache clear
  • created new directory
  • run yo angular test
  • run npm cache clear
  • run grunt serve
  • 修复节点安装
  • 打开高架cli
  • npm update -g
  • npm cache clear
  • npm install -g yo
  • npm cache clear
  • npm install -g generator-angular
  • npm cache clear
  • 创建了新目录
  • yo angular test
  • npm cache clear
  • grunt serve

I did run into some other issues with karma.conf.js where the paths had a \instead of /for bower_components. Also, I noticed the optional angular modules were injected in my app.js despite not including them all in my yo build from the cli. I have reported these issues on github.

我确实遇到了 karma.conf.js 的一些其他问题,其中路径有一个\而不是/bower_components。此外,我注意到可选的 angular 模块被注入到我的 app.js 中,尽管我没有将它们全部包含在我从 cli 构建的 yo 中。我已经在github上报告了这些问题。

回答by Kin

npm ERR! command "/home/ubuntu/local/bin/node"

错误!命令“/home/ubuntu/local/bin/node”

Are you installing in a user directory? I did and had ENOENT errors too.

您是在用户目录中安装吗?我做了并且也有 ENOENT 错误。

I had to mkdir some directories. If they're not there, try creating some of the directories in the debug.log, like lib/node_modules.

我不得不 mkdir 一些目录。如果它们不存在,请尝试在 debug.log 中创建一些目录,例如 lib/node_modules。

回答by Sam Mikes

These ENOENT(and sometimes EACCES) errors are often caused by old versions of npm. Unfortunately even the latest version of nodedoes not distribute the current version of npm.

这些ENOENT(有时EACCES)错误通常是由旧版本的npm. 不幸的是,即使是最新node版本的npm.

After installing node, run npm -v. If you don't see 2.1.18or later, you should upgrade following the official instructions here https://github.com/npm/npm/wiki/Troubleshooting#try-the-latest-stable-version-of-npm

安装后node,运行npm -v。如果您没有看到2.1.18或稍后,您应该按照此处的官方说明进行升级https://github.com/npm/npm/wiki/Troubleshooting#try-the-latest-stable-version-of-npm

On OSX the quick way to upgrade is sudo npm install -g npm@latest

在 OSX 上,快速升级的方法是 sudo npm install -g npm@latest

On Windows, follow the guide in the wiki or read this answer How do I update npm on Windows?

在 Windows 上,请按照 wiki 中的指南或阅读此答案如何在 Windows 上更新 npm?

cmd.exe cd C:\Program Files (x86)\nodejs npm install npm@latest

cmd.exe cd C:\Program Files (x86)\nodejs npm install npm@latest

回答by Nikola M.

Update node (and npm) to the latest version, and this should solve the issue.

将节点(和 npm)更新到最新版本,这应该可以解决问题。

回答by Daniele Vrut

My problem was a broken package.json. Maybe this will help someone.

我的问题是一个损坏的package.json。也许这会帮助某人。