Node.js错误: %1 不是一个有效的Win32应用程序。

7

您好,我从正在运行的Node.js服务器下载了我的项目副本,尝试运行它,但遇到以下错误:

错误:

E:\Projects\Smart Automation Web\Zigma_copy\automator\node_modules\bcrypt\node_modules\bindings\bindings.js:79
        throw e
              ^
Error: %1 is not a valid Win32 application.
E:\Projects\Smart Automation Web\Zigma_copy\automator\node_modules\bcrypt\build\Release\bcrypt_lib.node
    at Error (native)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Module.require (module.js:365:17)
    at require (module.js:384:17)
    at bindings (E:\Projects\Smart Automation Web\Zigma_copy\automator\node_modules\bcrypt\node_modules\bindings\bindings.js:74:15)
    at Object.<anonymous> (E:\Projects\Smart Automation Web\Zigma_copy\automator\node_modules\bcrypt\bcrypt.js:3:35)
    at Module._compile (module.js:460:26)
    at Object.Module._extensions..js (module.js:478:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Module.require (module.js:365:17)
    at require (module.js:384:17)
    at Object.<anonymous> (E:\Projects\Smart Automation Web\Zigma_copy\automator\api\services\UserManager.js:2:14)
    at Module._compile (module.js:460:26)
    at Object.Module._extensions..js (module.js:478:10)

我尝试运行我的应用程序的步骤如下:
  1. 使用FTP从我的服务器下载了完整的应用程序文件夹
  2. 通过WebStorm IDE打开项目
  3. 打开终端并输入:npm install
  4. 安装成功
  5. 然后我输入sails lift,但是出现以下错误。

作为一个新手,我无法找到它失败的原因。虽然我可以阅读错误信息,它说了一些关于我的UserManager.js的内容,因此我在这里附上它。

UserManager.js:

var jwt = require('jsonwebtoken')
var bcrypt = require('bcrypt');

var jwtSecret = "werisdkf120sdkfr84rwerf";
var ISSUER = "home-automator.com";
var EXPIRY_TIME = 120*500;

function genToken(user) {
  var token = jwt.sign({id: user.id}, jwtSecret, {issuer: ISSUER, expiresInMinutes: EXPIRY_TIME});
  return token;
}

module.exports = {
  hashPassword: function (plainTxtPassword, salt, next) {
    salt = salt || bcrypt.genSaltSync(6);
    bcrypt.hash(plainTxtPassword, salt, function (err, hash) {
      if (err) {
        return next({err: {message: "Something went wrong. Please try again later."}});
      }
      next(null, hash, salt);
    })
  },

  createUser: function (newUser, next) {
    User.findOneByEmail(newUser.email, function (err, user) {
      if (err) {
        return next({err: {message: "Failed to create user. Please try again later."}});
      }

      if (user) {
        return next({err: {message: "Email already registered. Please try a different email address."}})
      }

      User.create(newUser, function (err, user) {
        if (err) {
          return next({err: err});
        }

        next(null, user);
      })
    })
  },

  generateAuthToken: function (user) {
    return genToken(user);
  },

  generateAuthTokenFromPassword: function (username, password, next) {
    User.findOne({email: username}, function (err, user) {
      if (err) {
        return next({err: {message: "Something went wrong, please try again later."}});
      }

      if (!user) {
        return next({err: {message: "Invalid email address and/or password. Please enter valid login credentials and try again."}})
      }

      bcrypt.compare(password, user.encrypted_password, function (err, valid) {
        if (err) {
          return next({err: {message: "Something went wrong, please try again later."}});
        }
        if (!valid) {
          return next({err: {message: "Invalid email address and/or password. Please try again with valid login credentials."}});
        }
        else {
          next(null, user, genToken(user));
        }
      })
    })
  },

  getUserFromAuthToken: function (token, next) {
    jwt.verify(token, jwtSecret, {issuer: ISSUER}, function (err, user) {
      if (err) {
        return next(err);
      }

      User.findOne({id: user.id}, function (err, userData) {
        if (err) next(err);
        return next(null, userData);
      })
    })
  }
}

我删除了node_modules并重新运行npm install后得到了以下结果。现在,由于出现错误,似乎有一些包丢失:

E:\Projects\Smart Automation Web\Zigma_copy\automator>npm install
npm WARN deprecated jsonwebtoken@4.2.2: Critical vulnerability fix in v5.0.0. See https://auth0.com/blog/2015/03/31/critical-vulnerabilities-in-json-web-token-libraries/
npm WARN deprecated grunt-lib-contrib@0.7.1: DEPRECATED. See readme: https://github.com/gruntjs/grunt-lib-contrib
npm WARN deprecated jws@2.0.0: Security update: Versions below 3.0.0 are deprecated.
/


> bcrypt@0.8.3 install E:\Projects\Smart Automation Web\Zigma_copy\automator\node_modules\bcrypt
> node-gyp rebuild


E:\Projects\Smart Automation Web\Zigma_copy\automator\node_modules\bcrypt>node "C:\Program Files\nodejs\node_modules\npm\bin\node-gyp-bin\\..\..\node_modules\node-gyp\bin\node-gyp.js" rebuild
gyp ERR! configure error
gyp ERR! stack Error: Can't find Python executable "python", you can set the PYTHON env variable.
gyp ERR! stack     at failNoPython (C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\configure.js:103:14)
gyp ERR! stack     at C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\configure.js:64:11
gyp ERR! stack     at FSReqWrap.oncomplete (evalmachine.<anonymous>:99:15)
gyp ERR! System Windows_NT 6.3.9600
gyp ERR! command "node" "C:\\Program Files\\nodejs\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild"
gyp ERR! cwd E:\Projects\Smart Automation Web\Zigma_copy\automator\node_modules\bcrypt
gyp ERR! node -v v0.12.0
gyp ERR! node-gyp -v v1.0.2
ERR! not ok
-


> sails@0.11.0 preinstall E:\Projects\Smart Automation Web\Zigma_copy\automator\node_modules\sails
> node ./lib/preinstall_npmcheck.js

Sails.js Installation: Checking npm-version successful
\


> kerberos@0.0.7 install E:\Projects\Smart Automation Web\Zigma_copy\automator\node_modules\sails-mongo\node_modules\mongodb\node_modules\kerberos
> (node-gyp rebuild 2> builderror.log) || (exit 0)


E:\Projects\Smart Automation Web\Zigma_copy\automator\node_modules\sails-mongo\node_modules\mongodb\node_modules\kerberos>node "C:\Program Files\nodejs\node_modules\npm\bin\node-gyp-bin\\..\..\node_modules\node-gyp\bin\node-gyp.js" rebuild
/


> bson@0.2.21 install E:\Projects\Smart Automation Web\Zigma_copy\automator\node_modules\sails-mongo\node_modules\mongodb\node_modules\bson
> (node-gyp rebuild 2> builderror.log) || (exit 0)


E:\Projects\Smart Automation Web\Zigma_copy\automator\node_modules\sails-mongo\node_modules\mongodb\node_modules\bson>node "C:\Program Files\nodejs\node_modules\npm\bin\node-gyp-bin\\..\..\node_modules\node-gyp\bin\node-gyp.js" rebuild
-


> ws@0.5.0 install E:\Projects\Smart Automation Web\Zigma_copy\automator\node_modules\sails\node_modules\sails-hook-sockets\node_modules\socket.io\node_modules\engine.io\node_modules\ws
> (node-gyp rebuild 2> builderror.log) || (exit 0)

\
E:\Projects\Smart Automation Web\Zigma_copy\automator\node_modules\sails\node_modules\sails-hook-sockets\node_modules\socket.io\node_modules\engine.io\node_modules\ws>node "C:\Program Files\nodejs\node_modules\npm\bin\node-gyp-bin\\..\..\node_mo
dules\node-gyp\bin\node-gyp.js" rebuild
-
> ws@0.4.31 install E:\Projects\Smart Automation Web\Zigma_copy\automator\node_modules\sails\node_modules\sails-hook-sockets\node_modules\socket.io-client\node_modules\engine.io-client\node_modules\ws
> (node-gyp rebuild 2> builderror.log) || (exit 0)


E:\Projects\Smart Automation Web\Zigma_copy\automator\node_modules\sails\node_modules\sails-hook-sockets\node_modules\socket.io-client\node_modules\engine.io-client\node_modules\ws>node "C:\Program Files\nodejs\node_modules\npm\bin\node-gyp-bin\
\..\..\node_modules\node-gyp\bin\node-gyp.js" rebuild
npm ERR! Windows_NT 6.3.9600
npm ERR! argv "C:\\Program Files\\nodejs\\\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "install"
npm ERR! node v0.12.0
npm ERR! npm  v2.5.1
npm ERR! code ELIFECYCLE

npm ERR! bcrypt@0.8.3 install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the bcrypt@0.8.3 install script 'node-gyp rebuild'.
npm ERR! This is most likely a problem with the bcrypt package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node-gyp rebuild
npm ERR! You can get their info via:
npm ERR!     npm owner ls bcrypt
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     E:\Projects\Smart Automation Web\Zigma_copy\automator\npm-debug.log

如果你下载了完整的应用程序文件夹,那么你也会下载 node_modules 文件夹。因此,npm install 将会报告成功(当然),但是安装的模块,特别是本地模块,已经编译成针对目标机器的代码。请删除该文件夹并在您的主机上再次安装依赖包。 - Robert Rossmann
@RobertRossmann:你的意思是,我应该删除这个应用程序的node_modules文件夹,并在终端中再次运行npm install吗? - Rahul
是的。当应用程序移动到另一个操作系统时,我总是建议从头开始重新创建 node_modules - Robert Rossmann
@RobertRossmann: 感谢,我正在处理这个问题。虽然我看到了一些弃用警告和错误提示,但我很快会发布日志。 - Rahul
阅读日志 - 您的系统缺少Python。为了使本机插件正常工作(Sails使用),您需要确保node-gyp正常工作 - 请查看这些说明node-gypnpm的一部分,因此您无需单独安装它,但必须满足其先决条件)。 - Robert Rossmann
显示剩余3条评论
3个回答

7

我在尝试在 Windows 上部署时遇到了这个错误。

请在项目文件夹 node_modules (..programs\server\node_modules) 中删除包含 npm-bcrypt 的文件夹。

在部署服务器上运行以下命令:

npm install bcrypt

它会重新安装bcrypt以解决该错误。此外,您需要Python >2.5和<3.0才能正确处理纤维。如果您安装最新版本,则可能无法正常工作。


升级到较新版本的bcrypt对我来说是解决方案。在尝试了Roger K的解决方案之后。 - Yoruba
我在 DevOps 的构建步骤之后删除了服务器上的文件夹,并运行了 "npm install bcrypt --save"。但是这并没有起作用,出现了“bcrypt_lib.node 不是有效的 Win32 应用程序”的错误。 - ssedwards

0

您需要安装最新版本的Python。

使用开关--python="C:\Path\To\python.exe"

设置环境变量PYTHON

设置npm配置变量python:

npm config set python "C:\Path\To\python.exe"

检查是否在代理后运行?如果是,则管理代理以允许访问github.com。

一旦满足以上所有条件,然后运行以下命令。

npm install bcrypt

0

当我在Windows上使用x64node.js时,遇到了类似的问题。但是使用ia32node.js则没有问题。最后通过在~/.npmrc中添加arch=ia32解决了这个问题。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接