获取错误,错误:安装npm后无法找到模块'express' [英] Getting error, Error: Cannot find module ‘express’ after npm install

查看:233
本文介绍了获取错误,错误:安装npm后无法找到模块'express'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新的Node JS和express,我刚刚在Windows 7中安装了npm。

I am new to both Node JS and express, and I have just installed npm in Windows 7.

我已经使用全局标志安装了express:

I have installed express using the global flag:

npm install -g express

这成功地在 C:\Users\USER_NAME\AppData\Roaming\\\
pm\\\
ode_modules\express
中安装express,并添加 C:\Users\USER_NAME\AppData\Roaming\\\
pm
到我的路径。

This sucessfully installs express in C:\Users\USER_NAME\AppData\Roaming\npm\node_modules\express, and adds C:\Users\USER_NAME\AppData\Roaming\npm to my path.

然而,在命令行中使用express不成功。任何以express开头的命令告诉我找不到要执行的命令:

However, using express in the command line is not successful. Any command starting with express tells me it cannot find the command to execute:

 'express' is not recognized as an internal or external command,
  operable program or batch file.

查看安装文件夹,我找不到可执行文件(一个.exe或一个.CMD)。 Googling过去的问题表明,node_modules文件夹(至少在以前的版本中)应该包含一个express文件夹(我有)和一个 .bin 文件夹,其中包含 express.cmd 。我似乎没有 .bin 文件夹。

Looking in the installation folder, I can't find an executable file either (an .exe or a .cmd). Googling past questions shows that the node_modules folder (at least in past versions) should contain both an express folder (which I have) and a .bin folder, which contains express.cmd. I don't appear to have the .bin folder.

npm --version 给我 1.4.3 。 Express版本看起来是 3.0.0

npm --version gives me 1.4.3. Express version looks to be 3.0.0

我也尝试在本地安装,我试过运行 npm缓存清理并重新安装。两种方法都不会改变这种情况:node_modules文件夹中没有任何可执行文件。

I've also tried installing it locally, and I've tried running npm cache clean and reinstalling. Neither method changes the situation: there's nothing executable in the node_modules folder.

我是否正确安装Express?如果是这样,为什么不包括可执行文件?

推荐答案

我在Windows 8.1中遇到了同样的问题。没有创建express.cmd,但是我发现文本文件:

I ran into the same problem on Windows 8.1. The express.cmd is not created, but I found the text file:

C:\Users\you\AppData\Roaming\npm\node_modules\express\Readme.md

它建议运行这个:

npm install -g express-generator@3

哪些下载更多的东西。

之后,您可以使用 express Windows命令提示符。它将在您的路径(
C:\Users\you\AppData\Roaming\\\
pm)

After that you can use express on the windows command prompt. It will be in your path ( C:\Users\you\AppData\Roaming\npm)

编辑:

express-generator @ 3 现在更新为 express-generator @ 4
所以使用这个代替,

express-generator@3 is now updated to express-generator@4, so use this instead,

npm install -g express-generator@4

答案不完整,因为模块安装在 C:\Users\you \AppData\Roaming\\\
pm
目录,您不能随时访问任何模块,1)将其链接到当前项目或2)明确定义 NODE_PATH 系统变量将您的节点指向系统中的正确位置。

The answer isn't complete, because the modules are installed in C:\Users\you\AppData\Roaming\npm directory as stated above, and you cannot always access any module without, 1) linking it to your current project or 2) explicityly defining the NODE_PATH system variable pointing your node to the right place in the system.

第一种方法

安装模块后( express ),您可以使用cmd并执行以下命令,将其链接到当前项目,方法是使用目前的项目目录,

After installing the module (express in our case), you can link it to your current project by going to your current project directory using cmd and executing below command,

npm link express

你会收到这样的消息,如果它成功链接,

You will get a message like this if it is successfully linked,


D:\Project\\\
ode_modules\express - >
C:\Users\\ \\ Sufiyan\AppData\Roaming\\\
pm\\\
ode_modules\express

D:\Project\node_modules\express -> C:\Users\Sufiyan\AppData\Roaming\npm\node_modules\express

(您无法使用管理员连接cmd而不运行cmd权限)

(you cannot link directories without running cmd with Administrator privileges)

第二个选项是创建或更新将节点指向系统中正确位置的NODE_PATH系统变量。有关详细信息,请参阅

The second option is to create or update NODE_PATH system variable pointing your node to the right place in the system. Read this for details.

另请参阅有关该问题的官方Node.js文档,

Also read this official Node.js documentation regarding the issue,

http://blog.nodejs.org/2011/03/23/npm-1-0 -global-vs-local-installation /

这篇关于获取错误,错误:安装npm后无法找到模块'express'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆