node.js 节点 MODULE_NOT_FOUND
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/47083351/
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
Node MODULE_NOT_FOUND
提问by user3325126
I just upgraded to node version 9.0.0 and am now getting this error in the command line when trying to use npm install
我刚刚升级到节点版本 9.0.0,现在在尝试使用 npm install 时在命令行中收到此错误
npm ERR! code MODULE_NOT_FOUND
npm ERR! Cannot find module 'internal/util/types'
I'm using:
我正在使用:
- OSX 10.10.5
- Node version 9.0.0
- NPM version 5.5.1
- OSX 10.10.5
- 节点版本 9.0.0
- NPM 版本 5.5.1
Extra information: I am also trying to do this with a Laravel 5.5 project. This is how I update my version of node: How do I update Node.js?
额外信息:我也在尝试使用 Laravel 5.5 项目来做到这一点。这是我更新节点版本的方式:如何更新 Node.js?
回答by wrangler
run
跑
rm -rf /usr/local/lib/node_modules/npm
and then re-install Node.js will work in most cases
然后重新安装 Node.js 将在大多数情况下工作
回答by Hyman Vial
Leaving this here for anyone using the nnodejs version manager:
把这个n留给任何使用nodejs 版本管理器的人:
$ n 6.12.0 # Go back to a stable release
$ npm install -g npm@latest # Update npm to latest
$ n lts # Get 8.9.1
$ npm install #Should work now.
The MODULE_NOT_FOUND error seems to happen when changing between node versions and some files are possibly still being cached. I am not sure exactly but the above sequence of commands work for me.
在节点版本之间更改时似乎会发生 MODULE_NOT_FOUND 错误,并且某些文件可能仍在缓存中。我不确定,但上述命令序列对我有用。
回答by Adams
I got similar error also on Windows 8 after I have just upgraded node js. First: how I ran into the issue then the solution that worked for me.
在我刚刚升级节点 js 后,我在 Windows 8 上也遇到了类似的错误。首先:我是如何遇到这个问题的,然后是对我有用的解决方案。
How I ran to the issue:When I did npm --version and node --version I discovered that I wass running npm v3.x and node 5.x. So I went to nodejs.org site from where I downloaded node-v8.11.3-x64.msi. After installing the msi package I confirmed that my nodejs version was now v8.11.3 via node --version command.
我是如何解决这个问题的:当我执行 npm --version 和 node --version 时,我发现我正在运行 npm v3.x 和 node 5.x。所以我去了 nodejs.org 网站,从那里我下载了 node-v8.11.3-x64.msi。安装 msi 包后,我通过 node --version 命令确认我的 nodejs 版本现在是 v8.11.3。
Then, when I ran "npm install http-server" (w/o the quotes) that's when I got the issue:
然后,当我运行“npm install http-server”(不带引号)时,我遇到了问题:
npm ERR! node v8.11.3 npm ERR! npm v3.5.3 npm ERR! code MODULE_NOT_FOUND
错误!node v8.11.3 npm ERR!npm v3.5.3 npm ERR!代码 MODULE_NOT_FOUND
My resolution:I did some research including on the internet and found out that the npm version pointed to in my path was the one in my roaming profile C:\Users[myname.hostname]\AppData\Roaming\npm. In other words, the npm being used is not the one in the updated package I have just installed which is located in C:\Program Files\nodejs.
我的解决方案:我做了一些研究,包括在互联网上,发现我路径中指向的 npm 版本是我的漫游配置文件 C:\Users[myname.hostname]\AppData\Roaming\npm 中的版本。换句话说,正在使用的 npm 不是我刚刚安装的位于 C:\Program Files\nodejs 的更新包中的 npm。
The resolution was to delete npm and npm-cache in the roaming folder. Note, I used cygwin as I was not able to delete these folders via Windows cmd prompt. With cygwin, I navigated to
解决方案是删除漫游文件夹中的 npm 和 npm-cache 。请注意,我使用了 cygwin,因为我无法通过 Windows cmd 提示符删除这些文件夹。使用 cygwin,我导航到
cd "C:\Users[myname.hostname]\AppData\Roaming"
cd "C:\Users[myname.hostname]\AppData\Roaming"
Then I removed the aforementioned folders like so
然后我像这样删除了上述文件夹
rm -rf npm-cache rm -rf npm
rm -rf npm-cache rm -rf npm
After that, I opened a new Windows cmd prompt and was able to now successfully install http-server like so:
之后,我打开了一个新的 Windows cmd 提示符,现在可以像这样成功安装 http-server:
npm install http-server
npm 安装 http 服务器
Hope this works for you.
希望这对你有用。
回答by noman
If you are using libraries make sure to install everything with npm or yarn before starting. And in cases of you files if you are going to use them make sure to do the export.module thing everytime.
如果您正在使用库,请确保在开始之前使用 npm 或 yarn 安装所有内容。在你的文件的情况下,如果你打算使用它们,请确保每次都做 export.module 的事情。

