ssh2:模块解析失败:意外的字符'�'


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

如何解决?我在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"),
},
};

package.json

{
"type": "commonjs",
"private": true,
"scripts": {
"build": "webpack",
"start": "node ./dist/app.js"
},
"devDependencies": {
"dotenv": "^16.0.3",
"webpack": "^5.77.0",
"webpack-cli": "^5.0.1"
},
"dependencies": {
"mysql2": "^3.2.0",
"ssh2": "^1.11.0"
}
}

要处理Node.js附加组件,例如ssh2,您需要使用适当的加载器。因为它可以在Webpack页面上找到,您可以像下面这样使用node-loader:

module.exports = {
entry: "./src/app.js",
mode: "production",
output: {
filename: "app.js",
path: path.resolve(__dirname, "dist"),
},
module: {
rules: [
{
test: /.node$/,
loader: "node-loader",
},
],
},
};

别忘了安装:npm install --save-dev node-loader

相关内容

  • 没有找到相关文章

最新更新