Mr.*_*.AF 2 javascript commonjs node.js webpack
ERROR in ./node_modules/cpu-features/build/Release/cpufeatures.node 1:2\nModule parse failed: Unexpected character \'\xef\xbf\xbd\' (1:2)\nYou 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\n(Source code omitted for this binary file)\n @ ./node_modules/cpu-features/lib/index.js 3:16-60\n @ ./node_modules/ssh2/lib/protocol/constants.js 7:12-35\n @ ./node_modules/ssh2/lib/server.js 26:4-38\n @ ./node_modules/ssh2/lib/index.js 33:10-32\n @ ./src/app.js 3:19-34\n\nERROR in ./node_modules/ssh2/lib/protocol/crypto/build/Release/sshcrypto.node 1:2\nModule parse failed: Unexpected character \'\xef\xbf\xbd\' (1:2)\nYou 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\n(Source code omitted for this binary file)\n @ ./node_modules/ssh2/lib/protocol/crypto.js 30:12-60\n @ ./node_modules/ssh2/lib/server.js 27:29-60\n @ ./node_modules/ssh2/lib/index.js 33:10-32\n @ ./src/app.js 3:19-34\nRun Code Online (Sandbox Code Playgroud)\n如何解决呢?我找不到合适的装载机我在Webpack.org
\nwebpack.config.js
\nconst path = require("path");\n\nmodule.exports = {\n resolve: {\n fallback: {\n fs: false,\n tls: false,\n net: false,\n path: false,\n zlib: false,\n http: false,\n https: false,\n stream: false,\n crypto: false,\n buffer: false,\n util: false,\n assert: false,\n dns: false,\n process: false,\n timers: false,\n url: false,\n child_process: false,\n string_decoder: false,\n },\n },\n entry: "./src/app.js",\n mode: "production",\n output: {\n filename: "app.js",\n path: path.resolve(__dirname, "dist"),\n },\n};\nRun Code Online (Sandbox Code Playgroud)\n包.json
\n{\n "type": "commonjs",\n "private": true,\n "scripts": {\n "build": "webpack",\n "start": "node ./dist/app.js"\n },\n "devDependencies": {\n "dotenv": "^16.0.3",\n "webpack": "^5.77.0",\n "webpack-cli": "^5.0.1"\n },\n "dependencies": {\n "mysql2": "^3.2.0",\n "ssh2": "^1.11.0"\n }\n}\nRun Code Online (Sandbox Code Playgroud)\n
要处理 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",
},
],
},
};
Run Code Online (Sandbox Code Playgroud)
不要忘记安装它:npm install --save-dev node-loader
| 归档时间: |
|
| 查看次数: |
1008 次 |
| 最近记录: |