[英]Node JS Webpack Build Failed
I want to keep the Backend project I developed with Node JS as Build and keep it as 1 HTML file on my server as Webpack.我想将使用 Node JS 开发的后端项目保留为 Build,并将其作为 1 HTML 文件保存在我的服务器上,即 Webpack。 I am developing with nodemon, no problem, but according to my configuration the "NPM RUN BUILD" dwelling does not work.
我正在用 nodemon 开发,没问题,但是根据我的配置,“NPM RUN BUILD”住宅不起作用。 Could cause the problem?
会导致问题吗?
30 different errors return, this is one. 30 个不同的错误返回,这是一个。 All of them write other library information like this.
他们都像这样写其他图书馆信息。 "Module not found: Error: Can't resolve 'zlib' in '/ Users / ugurcanalyuz / Projects / Ekartex / ekartex_backend / node_modules / body-parser / lib'"
“未找到模块:错误:无法解析‘/Users/ugurcanalyuz/Projects/Ekartex/ekartex_backend/node_modules/body-parser/lib’中的‘zlib’”
webpack.config.js 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"
}
]
}
}
server.js服务器.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 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"
}
}
Just run the following command, inside you command line (/terminal):只需在命令行(/终端)内运行以下命令:
npm i zlib
devServer option is for client-side. devServer 选项用于客户端。 for node.js you need to add
对于 node.js 您需要添加
target: "node",
and also for better performance也为了更好的表现
const nodeWebExternals = require("webpack-node-externals");
// add this property to webpack config object
externals: [nodeWebExternals()],
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.