NodeJS MySQL连接失败

时间:2015-08-29 16:35:34

标签: mysql node.js

我刚刚添加了一个mysql连接,但脚本仍然失败。错误如下,相关的js低于该值。

TypeError: 'undefined' is not a function (evaluating 'loadClass.bind(null, 'Types')')

  app/node_modules/mysql/index.js:92
  app/node_modules/mysql/index.js:138
Error: Cannot find module 'crypto'

  phantomjs://bootstrap.js:289
  phantomjs://bootstrap.js:254 in require
  app/node_modules/mysql/lib/Connection.js:1
  app/node_modules/mysql/lib/Connection.js:420
TypeError: '[object Object]' is not a constructor (evaluating 'new Connection({config: new ConnectionConfig(config)})')

  app/node_modules/mysql/index.js:12 in createConnection

app.js

var Q = require("q");
var page = require('webpage').create();
//var crypto = require('./node_modules/crypto/sha1.js');
var mysql = require('mysql');

var connection = mysql.createConnection({
  host     : 'localhost',
  user     : 'shaun',
  password : 'somepassword',
  database : 'db'
});

connection.connect();

1 个答案:

答案 0 :(得分:0)

Error: Cannot find module 'crypto'

你试过npm install crypto吗?你的应用有一个package.json吗?如果有,你做了npm install