Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/429.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript node js在pc上抛出错误,但在Ubuntu上没有_Javascript_Windows_Node.js - Fatal编程技术网

Javascript node js在pc上抛出错误,但在Ubuntu上没有

Javascript node js在pc上抛出错误,但在Ubuntu上没有,javascript,windows,node.js,Javascript,Windows,Node.js,我正在尝试在我的windows计算机上启动我的node js服务器。在我的ubuntu上,一切正常,它启动了,但在windows上,我遇到以下错误: c:\xampp\htdocs\learningbankapi\src\node_modules\bcrypt\node_modules\bindings\bindings.js:79 throw e ^ Error: no errorc:\xampp\htdocs\learningbankapi

我正在尝试在我的windows计算机上启动我的node js服务器。在我的ubuntu上,一切正常,它启动了,但在windows上,我遇到以下错误:

    c:\xampp\htdocs\learningbankapi\src\node_modules\bcrypt\node_modules\bindings\bindings.js:79
        throw e
              ^
Error: no errorc:\xampp\htdocs\learningbankapi\src\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 (c:\xampp\htdocs\learningbankapi\src\node_modules\bcrypt\node_modules\bindings\bindings.js:74:15)
    at Object.<anonymous> (c:\xampp\htdocs\learningbankapi\src\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> (c:\xampp\htdocs\learningbankapi\src\auth.js:2:14)
    at Module._compile (module.js:460:26)
    at Object.Module._extensions..js (module.js:478:10)
我的节点模块包括:

有人能告诉我问题出在哪里吗?

你有没有从你的Ubuntu机器上复制node\u modules目录?您需要从副本中排除该目录,我建议您将该目录添加到.gitignore文件中,因为您尝试使用的模块很可能是为Linux系统编译的

如果您排除该目录并在Windows服务器上的该目录内运行npm install,则所有模块(包括bcrypt)都将重新生成以与Windows一起使用。

您是否从Ubuntu机器复制了node\u模块目录?您需要从副本中排除该目录,我建议您将该目录添加到.gitignore文件中,因为您尝试使用的模块很可能是为Linux系统编译的

如果排除该目录并在Windows服务器上的该目录内运行npm install,则所有模块(包括bcrypt)都将重新生成以与Windows一起使用。

您的问题是,您使用的节点模块依赖于无法在不同平台之间移植的本机代码

通常,共享node_modules文件夹不是一个好的做法。相反,只共享包依赖声明,每个开发人员都必须调用npm安装才能在项目上工作

这确保每个人都安装了在其平台上工作的软件包

如您所见,Dependes是一种用于编译本机插件的工具。因此,在您的情况下,问题的根源之一是您正在使用的节点模块依赖于无法在不同平台之间移植的本机代码

通常,共享node_modules文件夹不是一个好的做法。相反,只共享包依赖声明,每个开发人员都必须调用npm安装才能在项目上工作

这确保每个人都安装了在其平台上工作的软件包


如您所见,Dependes是一种用于编译本机插件的工具。因此,在您的情况下,这是问题的根源之一

如果我没记错的话,bcrypt需要安装VisualStudio。中也提到了这一点。我已经安装了VisualStudio。如果我没有记错,bcrypt需要安装VisualStudio。我已经安装了VisualStudio。
   var jwt = require('jwt-simple');
var bcrypt = require('bcrypt');
// Route: /login
module.exports = function (express, sequelize, router) {
    var DataTypes = require("sequelize");
    var User = sequelize.define('user', {
            id: DataTypes.INTEGER,
            username: DataTypes.STRING,
            password: DataTypes.STRING,
            organization_id: DataTypes.INTEGER,
            user_type_id: DataTypes.INTEGER,
            division_id: DataTypes.INTEGER


            }, {
            freezeTableName: true,
            instanceMethods: {
                retrieveByNamePassword: function (username, onSuccess, onError) {
                    User.find({include: [{ all: true }],where: {username: username}}, {})
                        .then(onSuccess).catch(onError);
                }
            }
        }
        ),
         Division = sequelize.define('division', {
            id: DataTypes.INTEGER,
            organization_id: DataTypes.INTEGER,
            location_id: DataTypes.INTEGER,
            name: DataTypes.STRING
        }, {freezeTableName: true}),
        Profile = sequelize.define('profile', {
            user_id: DataTypes.INTEGER,
            firstname: DataTypes.STRING,
            lastname: DataTypes.STRING,
            address: DataTypes.STRING,
            phone: DataTypes.STRING,
            cpr: DataTypes.STRING,
            description: DataTypes.STRING
        }, {freezeTableName: true}),
        Title = sequelize.define('title', {
            id: DataTypes.INTEGER,
            name: DataTypes.STRING,
            organization_id: DataTypes.INTEGER
        }, {freezeTableName: true});
    User.belongsTo(Division,{foreignKey: 'division_id'});
    User.hasOne(Profile, {foreignKey: 'user_id'});
    User.belongsTo(Title, {foreignKey:'title_id'});
    router.route('/login')

        .post(function (req, res) {
            var user = User.build();

            var username = req.body.username || '';
            var password = req.body.password || '';

            if (username == '' || password == '') {
                res.status(401);
                res.json({
                    "status": 401,
                    "message": "Invalid credentials"
                });
                return;
            }
            var salt = bcrypt.genSaltSync(10);
            var hash = bcrypt.hashSync(password, salt);


            user.retrieveByNamePassword(username, function (users) {
                var i = 0;
                if (bcrypt.compareSync(password,users.password)) {
                    // If authentication is success, we will generate a token
                    // and dispatch it to the client
                    res.json(genToken(users));
                    return;
                } else {
                    // If authentication fails, we send a 401 back
                    res.status(401);
                    res.json({
                        "status": 401,
                        "message": "Invalid credentials"
                    });
                    return;
                }
            }, function (error) {
                res.status(401);
                res.json({
                    "status": 401,
                    "message": "Invalid credentials"
                });
                return;
            });
        });

    var genToken = function(user) {
        var expires = expiresIn(7); // 7 days
        var token = jwt.encode({
            exp: expires,
            user_id: user.id,
            organization_id: user.organization_id,
            user_type_id: user.user_type_id,
            division_id: user.division_id

        }, require('./config/secret')());

        return {
            token: token,
            expires: expires,
            user: user
        };
    };

    var expiresIn = function(numDays) {
        var dateObj = new Date();
        return dateObj.setDate(dateObj.getDate() + numDays);
    };

    return router;
};