Nodejs找不到模块 [英] Nodejs Cannot find module

查看:100
本文介绍了Nodejs找不到模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在尝试使用任何全局模块时遇到错误,例子:

I'm getting an error when trying to use any global module, exemple:

Error: Cannot find module 'express'
    at Function.Module._resolveFilename (module.js:338:15)
    at Function.Module._load (module.js:280:25)
    at Module.require (module.js:362:17)
    at require (module.js:378:17)
    at Object.<anonymous> (C:\BitNami\wappstack\...\test\app.js)
    at Module._compile (module.js:449:26)
    at Object.Module._extensions..js (module.js:467:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.runMain (module.js:492:10)

我安装了 express 命令:

I installed the express command:

npm install -g express

我的 app.js:

var express = require('express');

并使用 windows powershell 或 node.js 命令提示符窗口运行它:

And run it using windows powershell or node.js command prompt windows:

node app.js

真的不知道怎么回事,我读了一些关于windows环境变量的内容,可以吗?

do not really know what's going wrong, I read something about environment variables in windows, can this be?

问题是:没有为 npm 文件夹配置 Windows 环境变量.搜索您的 npm 文件夹并在环境变量中添加路径.

The problem was: Windows environment variables was not configured for npm folder. Search for your npm folder and add the path in the environment variables.

推荐答案

你应该在本地安装 Express:

You should install Express locally:

npm install express

然后像你一样要求它:

var express = require('express')

这篇关于Nodejs找不到模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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