我正在尝试在我的Vagrant虚拟盒上运行node.js.当我尝试将node.js连接到我的数据库时,它会失败,如下所示。任何人都可以向我解释我应该如何解决它?
% sequelize -m
Loaded configuration file "config/config.json".
Using environment "development".
You need to install mysql package manually
TypeError: Cannot call method 'createConnection' of undefined
at module.exports.connect (/usr/local/lib/node_modules/sequelize/lib/dialects/mysql/connector-manager.js:259:28)
at Object.pool.Pooling.Pool.create (/usr/local/lib/node_modules/sequelize/lib/dialects/mysql/connector-manager.js:125:19)
at createResource (/usr/local/lib/node_modules/sequelize/node_modules/generic-pool/lib/generic-pool.js:258:13)
at dispense (/usr/local/lib/node_modules/sequelize/node_modules/generic-pool/lib/generic-pool.js:250:9)
at Object.me.acquire (/usr/local/lib/node_modules/sequelize/node_modules/generic-pool/lib/generic-pool.js:316:5)
at module.exports.enqueue (/usr/local/lib/node_modules/sequelize/lib/dialects/mysql/connector-manager.js:312:19)
at module.exports.ConnectorManager.query (/usr/local/lib/node_modules/sequelize/lib/dialects/mysql/connector-manager.js:164:15)
at module.exports.Sequelize.query (/usr/local/lib/node_modules/sequelize/lib/sequelize.js:252:34)
at null.<anonymous> (/usr/local/lib/node_modules/sequelize/lib/query-interface.js:689:32)
at null.<anonymous> (/usr/local/lib/node_modules/sequelize/lib/emitters/custom-event-emitter.js:26:18)
我可以保证我的数据库已启动并可运行且可连接:
% mysql -u root -pmyPassWord
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 45
Server version: 5.5.34-0ubuntu0.12.04.1 (Ubuntu)
Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
我还可以告诉你我已经使用npm安装了mysql包:
% sudo npm install -g mysql@2.0.0-alpha8
npm http GET https://registry.npmjs.org/mysql/2.0.0-alpha8
npm http 304 https://registry.npmjs.org/mysql/2.0.0-alpha8
npm http GET https://registry.npmjs.org/require-all/0.0.3
npm http GET https://registry.npmjs.org/bignumber.js/1.0.1
npm http 304 https://registry.npmjs.org/bignumber.js/1.0.1
npm http 304 https://registry.npmjs.org/require-all/0.0.3
mysql@2.0.0-alpha8 /home/vagrant/.nvm/v0.10.22/lib/node_modules/mysql
├── require-all@0.0.3
└── bignumber.js@1.0.1
% sudo npm install -g mysql
npm http GET https://registry.npmjs.org/mysql
npm http 304 https://registry.npmjs.org/mysql
npm http GET https://registry.npmjs.org/require-all/0.0.3
npm http GET https://registry.npmjs.org/bignumber.js/1.0.1
npm http 304 https://registry.npmjs.org/bignumber.js/1.0.1
npm http 304 https://registry.npmjs.org/require-all/0.0.3
mysql@2.0.0-rc2 /home/vagrant/.nvm/v0.10.22/lib/node_modules/mysql
├── require-all@0.0.3
└── bignumber.js@1.0.1
答案 0 :(得分:0)
我解决了这个问题。 问题是节点正在/ usr / local / lib / node_modules中寻找它的模块 但是npm正在〜/ .nvm / v0.10.22 / lib / node_modules中安装它们。
所以我将/ usr / local / lib / node_modules替换为〜/ .nvm / v0.10.22 / lib / node_modules的软链接