![](/img/trans.png)
[英]Webpack SyntaxError - Module build failed (from ./node_modules/babel-loader/lib/index.js)
[英]Node JS Webpack Build Failed
我想將使用 Node JS 開發的后端項目保留為 Build,並將其作為 1 HTML 文件保存在我的服務器上,即 Webpack。 我正在用 nodemon 開發,沒問題,但是根據我的配置,“NPM RUN BUILD”住宅不起作用。 會導致問題嗎?
30 個不同的錯誤返回,這是一個。 他們都像這樣寫其他圖書館信息。 “未找到模塊:錯誤:無法解析‘/Users/ugurcanalyuz/Projects/Ekartex/ekartex_backend/node_modules/body-parser/lib’中的‘zlib’”
webpack.config.js
const path = require("path");
module.exports = {
entry: './server.js',
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'bundle.js'
},
devServer: {
contentBase: './dist',
compress: true,
port: 3200
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
loader: "babel-loader"
}
]
}
}
服務器.js
const express = require("express");
const app = express();
const users = require("./src/routers/users");
app.use(users);
app.listen(3200, () => {
console.log("Sistem açık");
})
package.json
{
"name": "exxx",
"version": "1.0.0",
"description": "",
"main": "server.js",
"scripts": {
"start": "nodemon server.js",
"build": "webpack --mode production"
},
"repository": {
"type": "git"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"@babel/core": "^7.12.10",
"@babel/preset-env": "^7.12.11",
"babel-loader": "^8.2.2",
"webpack": "^5.11.1",
"webpack-cli": "^4.3.1",
"webpack-dev-server": "^3.11.1"
},
"dependencies": {
"express": "^4.17.1"
}
}
只需在命令行(/終端)內運行以下命令:
npm i zlib
devServer 選項用於客戶端。 對於 node.js 您需要添加
target: "node",
也為了更好的表現
const nodeWebExternals = require("webpack-node-externals");
// add this property to webpack config object
externals: [nodeWebExternals()],
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.