error: node_modules/bcrypto/build/Release/bcrypto.node: invalid ELF by npm start on debian server
error: node_modules/bcrypto/build/Release/bcrypto.node: invalid ELF by npm start on debian server
你好,
如果我尝试 npm start
我得到这个错误:
error: /home/kyrill/msh/backend/node_modules/bcrypto/build/Release/bcrypto.node: invalid ELF header /home/kyrill/msh/backend/node_modules/bcrypto/build/Release/bcrypto.node: invalid ELF header {"code":"ERR_DLOPEN_FAILED","stack":"Error: /home/kyrill/msh/backend/node_modules/bcrypto/build/Release/bcrypto.node: invalid ELF header\n at load (/home/kyrill/msh/backend/node_modules/loady/lib/loady.js:109:11)\n at Object.<anonymous> (/home/kyrill/msh/backend/node_modules/bcrypto/lib/native/binding.js:11:33)\n at Module._compile (node:internal/modules/cjs/loader:1092:14)\n at Object.Module._extensions..js (node:internal/modules/cjs/loader:1121:10)\n at Module.load (node:internal/modules/cjs/loader:972:32)\n at Function.Module._load (node:internal/modules/cjs/loader:813:14)\n at Module.require (node:internal/modules/cjs/loader:996:19)\n at require (node:internal/modules/cjs/helpers:92:18)\n at Object.<anonymous> (/home/kyrill/msh/backend/node_modules/bcrypto/lib/native/hkdf.js:10:17)\n at Module._compile (node:internal/modules/cjs/loader:1092:14)"}
error: /home/kyrill/msh/backend/node_modules/bcrypto/build/Release/bcrypto.node: invalid ELF header Error: /home/kyrill/msh/backend/node_modules/bcrypto/build/Release/bcrypto.node: invalid ELF header
不知道怎么解决...
api.js
const express = require('express');
const cors = require('cors');
const upload = require('express-fileupload');
const dotenv = require('dotenv').config();
const winston = require('winston');
const authRoute = require('./routes/auth');
const uploadRoute = require('./routes/upload');
const gutachtenRoute = require('./routes/gutachten');
const userRoute = require('./routes/user');
const db = require('./lib/db');
const auth = require('./middleware/auth');
const role = require('./middleware/role');
const app = express();
require('./lib/logging')();
db.init().then(() => winston.info("Orbit DB connected"));
app.use(cors());
app.use(express.json());
app.use(upload());
app.use('/api/auth', authRoute);
app.use('/api/upload', auth, uploadRoute);
app.use('/api/gutachten', auth, gutachtenRoute);
app.use('/api/user', [auth, role], userRoute);
app.listen(process.env.API_PORT, () => winston.info('API Start: http://127.0.0.1:' + process.env.API_PORT));
使用bcrypt的地方:
user.js是模特
const router = require('express').Router();
const User = require('../models/user');
const bcrypt = require('bcryptjs');
router.get('/getall', async (req, res) => {
res.send(User.getAll());
})
router.post('/add', async (req, res) => {
const { error } = User.validateRegister(req.body);
if(error) return res.status(422).send(error.details[0].message);
const user = await User.findOne(req.body.email);
if(user) return res.status(400).send('User with this email already exist');
const salt = await bcrypt.genSalt(10);
req.body.password = await bcrypt.hash(req.body.password, salt);
res.send(User.create(req.body));
});
router.post('/update', async (req, res) => {
const { error } = User.validateUpdate(req.body);
if(error) return res.status(422).send(error.details[0].message);
const user = await User.findOne(req.body.email);
if(!user) return res.status(400).send('User with this email not exist');
if(req.body.password) {
const salt = await bcrypt.genSalt(10);
req.body.password = await bcrypt.hash(req.body.password, salt);
} else {
req.body.password = user.password;
}
await User.update(req.body);
res.send(User.getAll());
})
router.post('/del', async (req, res) => {
// const { error } = User.validateDelete(req.body);
// if(error) return res.status(422).send(error.details[0].message);
const user = await User.findOne(req.body.email);
if(!user) return res.status(400).send('User with this email not exist');
await User.delete(req.body);
res.send(User.getAll());
})
module.exports = router;
auth.js 是路线:
const router = require('express').Router();
const bcrypt = require('bcryptjs');
const User = require('../models/user');
router.post('/login', async (req, res) => {
const { error } = User.validateLogin(req.body);
if(error) return res.status(422).send(error.details[0].message);
const user = await User.findOne(req.body.email);
if(!user) res.status(404).send('Invalid email or password');
const validPassword = await bcrypt.compare(req.body.password, user.password);
if(!validPassword) res.status(404).send('Invalid email or password');
const token = User.generateAuthToken(req.body)
res.json(token);
})
module.exports = router;
在我的 macOS 上本地运行没有问题
我也尝试使用 --force 修复 npm audit fix,但出现此错误:
npm ERR! command git --no-replace-objects ls-remote ssh://git@github.com/haadcode/ipfs-pubsub-room.git
npm ERR! git@github.com: Permission denied (publickey).
npm ERR! fatal: Could not read from remote repository.
此外,我尝试使用 npm i bcryptjs
从新安装它
我认为您是在 MAC-OS 和 运行 上创建了 debian OS 上的构建。这(无效的 ELF header)发生在你在一个架构上构建然后尝试在不同的架构(或某些情况下的平台)上使用相同的构建插件时。
你可以在 debian 服务器上做什么,删除 node modules
并重新生成它们可以解决问题:
删除节点模块:
rm -rf node_modules/
然后使用以下命令为 linux 生成相同的模块:
npm update
看起来您已经安装了 bcrypto
包,该包正在使用本机插件,但由于某种原因无法安装在您使用的机器上。执行 npm uninstall bcrypto
,卸载它就可以了,因为您使用的 bcryptjs
版本不使用本机功能。
你好,
如果我尝试 npm start
我得到这个错误:
error: /home/kyrill/msh/backend/node_modules/bcrypto/build/Release/bcrypto.node: invalid ELF header /home/kyrill/msh/backend/node_modules/bcrypto/build/Release/bcrypto.node: invalid ELF header {"code":"ERR_DLOPEN_FAILED","stack":"Error: /home/kyrill/msh/backend/node_modules/bcrypto/build/Release/bcrypto.node: invalid ELF header\n at load (/home/kyrill/msh/backend/node_modules/loady/lib/loady.js:109:11)\n at Object.<anonymous> (/home/kyrill/msh/backend/node_modules/bcrypto/lib/native/binding.js:11:33)\n at Module._compile (node:internal/modules/cjs/loader:1092:14)\n at Object.Module._extensions..js (node:internal/modules/cjs/loader:1121:10)\n at Module.load (node:internal/modules/cjs/loader:972:32)\n at Function.Module._load (node:internal/modules/cjs/loader:813:14)\n at Module.require (node:internal/modules/cjs/loader:996:19)\n at require (node:internal/modules/cjs/helpers:92:18)\n at Object.<anonymous> (/home/kyrill/msh/backend/node_modules/bcrypto/lib/native/hkdf.js:10:17)\n at Module._compile (node:internal/modules/cjs/loader:1092:14)"}
error: /home/kyrill/msh/backend/node_modules/bcrypto/build/Release/bcrypto.node: invalid ELF header Error: /home/kyrill/msh/backend/node_modules/bcrypto/build/Release/bcrypto.node: invalid ELF header
不知道怎么解决...
api.js
const express = require('express');
const cors = require('cors');
const upload = require('express-fileupload');
const dotenv = require('dotenv').config();
const winston = require('winston');
const authRoute = require('./routes/auth');
const uploadRoute = require('./routes/upload');
const gutachtenRoute = require('./routes/gutachten');
const userRoute = require('./routes/user');
const db = require('./lib/db');
const auth = require('./middleware/auth');
const role = require('./middleware/role');
const app = express();
require('./lib/logging')();
db.init().then(() => winston.info("Orbit DB connected"));
app.use(cors());
app.use(express.json());
app.use(upload());
app.use('/api/auth', authRoute);
app.use('/api/upload', auth, uploadRoute);
app.use('/api/gutachten', auth, gutachtenRoute);
app.use('/api/user', [auth, role], userRoute);
app.listen(process.env.API_PORT, () => winston.info('API Start: http://127.0.0.1:' + process.env.API_PORT));
使用bcrypt的地方:
user.js是模特
const router = require('express').Router();
const User = require('../models/user');
const bcrypt = require('bcryptjs');
router.get('/getall', async (req, res) => {
res.send(User.getAll());
})
router.post('/add', async (req, res) => {
const { error } = User.validateRegister(req.body);
if(error) return res.status(422).send(error.details[0].message);
const user = await User.findOne(req.body.email);
if(user) return res.status(400).send('User with this email already exist');
const salt = await bcrypt.genSalt(10);
req.body.password = await bcrypt.hash(req.body.password, salt);
res.send(User.create(req.body));
});
router.post('/update', async (req, res) => {
const { error } = User.validateUpdate(req.body);
if(error) return res.status(422).send(error.details[0].message);
const user = await User.findOne(req.body.email);
if(!user) return res.status(400).send('User with this email not exist');
if(req.body.password) {
const salt = await bcrypt.genSalt(10);
req.body.password = await bcrypt.hash(req.body.password, salt);
} else {
req.body.password = user.password;
}
await User.update(req.body);
res.send(User.getAll());
})
router.post('/del', async (req, res) => {
// const { error } = User.validateDelete(req.body);
// if(error) return res.status(422).send(error.details[0].message);
const user = await User.findOne(req.body.email);
if(!user) return res.status(400).send('User with this email not exist');
await User.delete(req.body);
res.send(User.getAll());
})
module.exports = router;
auth.js 是路线:
const router = require('express').Router();
const bcrypt = require('bcryptjs');
const User = require('../models/user');
router.post('/login', async (req, res) => {
const { error } = User.validateLogin(req.body);
if(error) return res.status(422).send(error.details[0].message);
const user = await User.findOne(req.body.email);
if(!user) res.status(404).send('Invalid email or password');
const validPassword = await bcrypt.compare(req.body.password, user.password);
if(!validPassword) res.status(404).send('Invalid email or password');
const token = User.generateAuthToken(req.body)
res.json(token);
})
module.exports = router;
在我的 macOS 上本地运行没有问题
我也尝试使用 --force 修复 npm audit fix,但出现此错误:
npm ERR! command git --no-replace-objects ls-remote ssh://git@github.com/haadcode/ipfs-pubsub-room.git
npm ERR! git@github.com: Permission denied (publickey).
npm ERR! fatal: Could not read from remote repository.
此外,我尝试使用 npm i bcryptjs
我认为您是在 MAC-OS 和 运行 上创建了 debian OS 上的构建。这(无效的 ELF header)发生在你在一个架构上构建然后尝试在不同的架构(或某些情况下的平台)上使用相同的构建插件时。
你可以在 debian 服务器上做什么,删除 node modules
并重新生成它们可以解决问题:
删除节点模块:
rm -rf node_modules/
然后使用以下命令为 linux 生成相同的模块:
npm update
看起来您已经安装了 bcrypto
包,该包正在使用本机插件,但由于某种原因无法安装在您使用的机器上。执行 npm uninstall bcrypto
,卸载它就可以了,因为您使用的 bcryptjs
版本不使用本机功能。