ERROR in ./node_modules/cpu-features/build/Release/cpufeatures.node 1:2
Module parse failed: Unexpected character '�' (1:2)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
(Source code omitted for this binary file)
@ ./node_modules/cpu-features/lib/index.js 3:16-60
@ ./node_modules/ssh2/lib/protocol/constants.js 7:12-35
@ ./node_modules/ssh2/lib/server.js 26:4-38
@ ./node_modules/ssh2/lib/index.js 33:10-32
@ ./src/app.js 3:19-34
ERROR in ./node_modules/ssh2/lib/protocol/crypto/build/Release/sshcrypto.node 1:2
Module parse failed: Unexpected character '�' (1:2)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
(Source code omitted for this binary file)
@ ./node_modules/ssh2/lib/protocol/crypto.js 30:12-60
@ ./node_modules/ssh2/lib/server.js 27:29-60
@ ./node_modules/ssh2/lib/index.js 33:10-32
@ ./src/app.js 3:19-34
How to resolve it? I couldn’t find the right loader in Webpack.org
webpack.config.js
const path = require("path");
module.exports = {
resolve: {
fallback: {
fs: false,
tls: false,
net: false,
path: false,
zlib: false,
http: false,
https: false,
stream: false,
crypto: false,
buffer: false,
util: false,
assert: false,
dns: false,
process: false,
timers: false,
url: false,
child_process: false,
string_decoder: false,
},
},
entry: "./src/app.js",
mode: "production",
output: {
filename: "app.js",
path: path.resolve(__dirname, "dist"),
},
};
app.js
const conf = require("./config.js");
const mysql = require("mysql2");
const { Client } = require("ssh2");
// create an instance of SSH Client
const sshClient = new Client();
const SSHConnection = new Promise((resolve, reject) => {
sshClient
.on("ready", () => {
sshClient.forwardOut(
conf.forwardConfig.srcHost,
conf.forwardConfig.srcPort,
conf.forwardConfig.dstHost,
conf.forwardConfig.dstPort,
(err, stream) => {
if (err) reject(err);
// create a new DB server object including stream
const updatedDbServer = {
...dbServer,
stream,
};
// connect to mysql
const connection = mysql.createConnection(updatedDbServer);
// check for successful connection
// resolve or reject the Promise accordingly
connection.connect((error) => {
if (error) {
reject(error);
}
resolve(connection);
});
}
);
})
.connect(conf.tunnelConfig);
});
SSHConnection.then(
(resolve) => {
console.log("ssh resolved");
},
(reject) => {
console.log(`ssh reject: ${reject}`);
}
);