Reputation: 344
Hallo,
If I try to npm start
I get this error:
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
I don't know how to solve it ...
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));
places where bcrypt is used:
user.js is a model
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 is routes:
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;
local on my macos it work without problems
I tried to npm audit fix also with --force , but I get this error:
npm ERR! command git --no-replace-objects ls-remote ssh://[email protected]/haadcode/ipfs-pubsub-room.git
npm ERR! [email protected]: Permission denied (publickey).
npm ERR! fatal: Could not read from remote repository.
Also, I tried to install it from new with npm i bcryptjs
Upvotes: 0
Views: 3519
Reputation: 8773
I think you are creating the build on MAC-OS and running that on debian OS. This(invalid ELF header) happens when you build on one architecture and then attempt to use the same built addon on a different architecture (or platform in some cases).
What you can do on the debian server, remove the node modules
and regenerate them that could solve the problem:
Remove the node modules:
rm -rf node_modules/
Then generate the same modules for linux using the following command:
npm update
Upvotes: 2
Reputation: 2465
Looks like you have installed bcrypto
package that is using the native addon, that for some reason cannot be installed on the machine you are using. Do npm uninstall bcrypto
, it is okay to just uninstall it, as you are using bcryptjs
version that does not use native features.
Upvotes: 0