TypeError: The "digest" argument is required and must not be undefined

TypeError: The "digest" argument is required and must not be undefined

我在通过 http://localhost:3000/auth/register 注册一个简单的平均应用程序时遇到主题错误,我只是使用 mean init 命令创建的。 pbkdf2crypto 正在生成错误,我不知道在哪里寻找它。

我做了很多不同的事情,比如清除 npm 缓存,使用 npm 重新安装等。请帮助我。以下是更多信息。

Mean --version: 0.12.15
npm --version: 5.0.3
node --version: v8.1.0
bower --version: 1.8.0
gulp --version: CLI and Local: 3.9.1

model.UserSchema.methods.hashPassword 的代码(D:\Projects\Mean\CampaignBuilder\node_modules\meanio-users\server\models\user.js)

/**
 * Hash password
 *
 * @param {String} password
 * @return {String}
 * @api public
 */
UserSchema.methods.hashPassword = function(password) {
  if (!password || !this.salt) return '';
  var salt = new Buffer(this.salt, 'base64');
  return crypto.pbkdf2Sync(password, salt, 10000, 64).toString('base64');
};

注册页面调用 http://localhost:3000/api/register 并生成 500 Internal Server Error

Firefox 显示以下响应:

TypeError: The "digest" argument is required and must not be undefined
at pbkdf2 (crypto.js:635:11)
at Object.exports.pbkdf2Sync (crypto.js:628:10)
at model.UserSchema.methods.hashPassword (D:\Projects\Mean\CampaignBuilder\node_modules\meanio-users\server\models\user.js:165:17)
at model.<anonymous> (D:\Projects\Mean\CampaignBuilder\node_modules\meanio-users\server\models\user.js:94:31)
at VirtualType.applySetters (D:\Projects\Mean\CampaignBuilder\node_modules\mongoose\lib\virtualtype.js:94:25)
at model.Document.set (D:\Projects\Mean\CampaignBuilder\node_modules\mongoose\lib\document.js:656:12)
at model._handleIndex (D:\Projects\Mean\CampaignBuilder\node_modules\mongoose\lib\document.js:587:14)
at model.Document.set (D:\Projects\Mean\CampaignBuilder\node_modules\mongoose\lib\document.js:547:24)
at model.Document (D:\Projects\Mean\CampaignBuilder\node_modules\mongoose\lib\document.js:71:12)
at model.Model (D:\Projects\Mean\CampaignBuilder\node_modules\mongoose\lib\model.js:46:12)
at new model (D:\Projects\Mean\CampaignBuilder\node_modules\mongoose\lib\model.js:3621:13)
at create (D:\Projects\Mean\CampaignBuilder\node_modules\meanio-users\server\controllers\users.js:86:24)
at Layer.handle [as handle_request] (D:\Projects\Mean\CampaignBuilder\node_modules\meanio\lib\core_modules\server\node_modules\express\lib\router\layer.js:95:5)
at next (D:\Projects\Mean\CampaignBuilder\node_modules\meanio\lib\core_modules\server\node_modules\express\lib\router\route.js:137:13)
at Route.dispatch (D:\Projects\Mean\CampaignBuilder\node_modules\meanio\lib\core_modules\server\node_modules\express\lib\router\route.js:112:3)
at Layer.handle [as handle_request] (D:\Projects\Mean\CampaignBuilder\node_modules\meanio\lib\core_modules\server\node_modules\express\lib\router\layer.js:95:5)
at D:\Projects\Mean\CampaignBuilder\node_modules\meanio\lib\core_modules\server\node_modules\express\lib\router\index.js:281:22
at Function.process_params (D:\Projects\Mean\CampaignBuilder\node_modules\meanio\lib\core_modules\server\node_modules\express\lib\router\index.js:335:12)
at next (D:\Projects\Mean\CampaignBuilder\node_modules\meanio\lib\core_modules\server\node_modules\express\lib\router\index.js:275:10)
at loadUser (D:\Projects\Mean\CampaignBuilder\node_modules\meanio-users\server\controllers\users.js:202:24)
at Layer.handle [as handle_request] (D:\Projects\Mean\CampaignBuilder\node_modules\meanio\lib\core_modules\server\node_modules\express\lib\router\layer.js:95:5)
at trim_prefix (D:\Projects\Mean\CampaignBuilder\node_modules\meanio\lib\core_modules\server\node_modules\express\lib\router\index.js:317:13)
at D:\Projects\Mean\CampaignBuilder\node_modules\meanio\lib\core_modules\server\node_modules\express\lib\router\index.js:284:7
at Function.process_params (D:\Projects\Mean\CampaignBuilder\node_modules\meanio\lib\core_modules\server\node_modules\express\lib\router\index.js:335:12)
at next (D:\Projects\Mean\CampaignBuilder\node_modules\meanio\lib\core_modules\server\node_modules\express\lib\router\index.js:275:10)
at D:\Projects\Mean\CampaignBuilder\node_modules\connect-modrewrite\index.js:129:7
at Layer.handle [as handle_request] (D:\Projects\Mean\CampaignBuilder\node_modules\meanio\lib\core_modules\server\node_modules\express\lib\router\layer.js:95:5)
at trim_prefix (D:\Projects\Mean\CampaignBuilder\node_modules\meanio\lib\core_modules\server\node_modules\express\lib\router\index.js:317:13)

根据 crypto.pbkdf2Sync 方法,您缺少最后一个参数 digest,因此显示错误。

crypto.pbkdf2

通过进一步调查,您还可以看到节点 v6.0 中需要摘要参数。

之前的默认值好像是'sha1'

这也可能是由于节点版本错误引起的/运行正在使用的节点版本不支持调用的版本

我的经验:我的团队有一个应用程序需要 Node 6.10.0。有时我忘记切换到这个版本的节点和 运行 8.6.0 下的最新代码,我收到同样的错误。一旦我切换回 6.10.0,该网站将允许我登录。

(我可以看到已接受的答案也提到了这一点,但我想添加一个更明显的答案,以防它能帮助那里的人!)