找不到模块`mysql` node.js [英] Cannot find module `mysql` node.js
问题描述
我是nodejs的新手.要连接mysql,我使用以下命令在节点上安装了mysql
i am a newbie to nodejs. To connect mysql, i installed mysql
on node using the command,
npm install mysql
安装时没有出现任何错误.然后我尝试执行以下代码,
I didn't get any error while installing. Then i tried executing the following code,
var mysql = require("mysql");
但是它在尝试执行该错误时显示了以下错误.
But it is showing the following error while im trying to execute that.
C:\node\mysql>node app.js
module.js:340
throw err;
^
Error: Cannot find module 'mysql'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (C:\node\mysql\app.js:1:75)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
我尝试了一些建议,例如使用全局安装mysql,
I tried some suggestion like installing mysql globally using,
npm install -g mysql
但是没有任何效果.请帮助!!!
But nothing works. Help please!!!
请注意我的工作环境,
操作系统:Windows7 节点版本:0.10.15 NPM版本:1.3.5
OS: Windows7 Node version: 0.10.15 NPM version: 1.3.5
推荐答案
我只是遇到了同样的问题,发现原因是该模块安装在以下位置:
I just ran into the same problem and found it was because the module was installed in:
./node_modules/node-mysql/node_modules/
所以,我将它们全部移走了:
So, I just moved them all:
mv ./node_modules/node-mysql/node_modules/* ./node_modules/
这篇关于找不到模块`mysql` node.js的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!