【问题标题】:cannot install mysql using npm in nodejs无法在 nodejs 中使用 npm 安装 mysql
【发布时间】:2012-07-23 11:10:37
【问题描述】:

我试过以下命令,mysql模块没有被添加到node_module文件夹中,使用mysql的代码也抛出错误。

   Your environment has been set up for using Node.js 0.8.3 (ia32) and NPM

C:\Users\Work>npm install mysql
npm http GET https://registry.npmjs.org/mysql
npm http 304 https://registry.npmjs.org/mysql
npm http GET https://registry.npmjs.org/hashish/0.0.4
npm http 304 https://registry.npmjs.org/hashish/0.0.4
npm http GET https://registry.npmjs.org/traverse
npm http 304 https://registry.npmjs.org/traverse
mysql@0.9.6 node_modules\mysql
└── hashish@0.0.4 (traverse@0.6.3)

C:\Users\Work>npm install mysql@2.0.0-alpha3
npm http GET https://registry.npmjs.org/mysql/2.0.0-alpha3
npm http 304 https://registry.npmjs.org/mysql/2.0.0-alpha3
npm http GET https://registry.npmjs.org/require-all/0.0.3
npm http 304 https://registry.npmjs.org/require-all/0.0.3
mysql@2.0.0-alpha3 node_modules\mysql
└── require-all@0.0.3

C:\Users\Work>node D:\nodejs\sqlwrite.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:362:17)
    at require (module.js:378:17)
    at Object.<anonymous> (D:\nodejs\sqlwrite.js:1:74)
    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)

C:\Users\Work>

我已经输入了github上显示的命令。

【问题讨论】:

  • 您应该添加系统变量的路径。 IE;安装 mysql mudule 的路径。
  • 您使用的是哪个操作系统?
  • Windows 7(64 位)-终极版。 mysql 模块未添加到 node_module 文件夹中。

标签: mysql node.js


【解决方案1】:

您应该将路径(安装节点模块的位置)添加到系统变量。或者导航到 NodeJS 模块的默认系统路径并安装 NodeJS 模块。这是我系统的路径:

C:\Users\[user-name]\AppData\Roaming\npm\node_modules

【讨论】:

  • 我将模块从“C:\Users\Work\node_modules\mysql”复制到“C:\Program Files (x86)\nodejs\node_modules”中的 nodejs 文件夹中。还是一样的错误。
  • 查看该路径是否包含在系统变量Path中?
  • >C:\Program Files (x86)\nodejs\ 包含在系统变量路径中。
  • 谢谢我需要以管理员身份运行 node.js 命令提示符,解决了问题
猜你喜欢
  • 1970-01-01
  • 2017-12-07
  • 2019-05-27
  • 2016-08-14
  • 2016-11-23
  • 1970-01-01
  • 2020-10-21
  • 2021-01-21
  • 1970-01-01
相关资源
最近更新 更多