【问题标题】:Sequelize Error - lodash has no method "template"Sequelize Error - lodash 没有方法“模板”
【发布时间】:2014-05-27 02:05:51
【问题描述】:

我刚刚通过 npm 安装了 Sequelize 和 MySQL 模块,但遇到了错误。

我可以成功查询我的模型,但尝试创建新模型实例会导致 query-generator.js 文件中出现错误。

我的代码:

var Sequelize = require('sequelize')
  , sequelize = new Sequelize('databasename', 'username', 'password');

var User = sequelize.define('users', {
  email: Sequelize.STRING,
  fname: Sequelize.STRING,
  lname: Sequelize.STRING,
});

// WORKS
User.find(1)
  .success(function(user) {
    console.log('User found');
  }).
  error(function(err) {
    console.log('Error locating user', err);
  });

// FAILS
User.create({
  email : 'test@example.com',
  fname : 'John',
  lname : 'Doe'
})
.success(function(user) {
  // Do something
})
.error(function(err) {
  // Do something
});

这是错误

~/Project/node_modules/sequelize/lib/dialects/abstract/query-generator.js:156
      return Utils._.template(query)(replacements)
                 ^
TypeError: Object function lodash(value) {
      // don't wrap if already wrapped, even if wrapped by a different `lodash` constructor
      return (value && typeof value == 'object' && !isArray(value) && hasOwnProperty.call(value, '__wrapped__'))
   ? value
   : new lodashWrapper(value);
} has no method 'template'
at Object.module.exports.QueryGenerator.insertQuery (~/Project/node_modules/sequelize/lib/dialects/abstract/query-generator.js:156:22)

【问题讨论】:

  • 我知道 lodash 有一个模板方法。但问题是,为什么 Sequelize 包会给我这个错误?我找不到任何其他记录在案的案例。
  • 你用的是mysql吧?你也安装了 mysql 包吗?
  • 啊,你做到了。你用的是哪个版本的sequelize和mysql?
  • 有趣的是,我打开了 Sequelize 附带的 lodash 节点模块,描述为“Lo-dash lib 的私有版本,没有 template() 方法来绕过 CSP 限制”

标签: mysql node.js sequelize.js


【解决方案1】:

事实证明,我的本地 npm 版本正在获取 Emmet 特定的 lodash 版本。跑步

npm install lodash

获取此 repo https://github.com/emmetio/lodash 而不是 https://github.com/lodash/lodash

跑步

npm install lodash --force

并重新安装 Sequelize 纠正了我的问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-02-22
    • 2020-08-28
    • 2020-10-30
    • 1970-01-01
    • 1970-01-01
    • 2017-09-04
    • 1970-01-01
    相关资源
    最近更新 更多