简体   繁体   English

节点 JS Webpack 构建失败

[英]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.

相关问题 Webpack SyntaxError - 模块构建失败(来自./node_modules/babel-loader/lib/index.js) - Webpack SyntaxError - Module build failed (from ./node_modules/babel-loader/lib/index.js) 模块构建失败:未知词(2:9)| bundle / webpack的问题(react,redux,js,node) - Module build failed: Unknown word (2:9) | Problem with bundle/webpack (react, redux, js, node) Webpack:出现此错误:构建失败(来自./node_modules/css-loader/dist/cjs.js): - Webpack: getting this error: build failed (from ./node_modules/css-loader/dist/cjs.js): 错误:模块构建失败(来自./node_modules/@angular-devkit/build-angular/src/babel/webpack-loader.js): - Error: Module build failed (from ./node_modules/@angular-devkit/build-angular/src/babel/webpack-loader.js): 模块构建失败(来自./node_modules/@nuxt/webpack/node_modules/babel-loader/lib/index.js): - Module build failed (from ./node_modules/@nuxt/webpack/node_modules/babel-loader/lib/index.js): ./src/main.ts - 错误:模块构建失败(来自./node_modules/@angular-devkit/build-angular/node_modules/@ngtools/webpack/src/ivy/index.js): - ./src/main.ts - Error: Module build failed (from ./node_modules/@angular-devkit/build-angular/node_modules/@ngtools/webpack/src/ivy/index.js): Webpack 构建 Angular.js - 无法实例化模块应用程序 - Webpack build Angular.js - Failed to instantiate module app 在 Node.js 脚本中触发 webpack 无命令行构建 - Trigger webpack build WITHOUT command line in Node.js script Webpack没有编译 - 模块构建失败 - Webpack not compiling - Module build failed 由于uglifyJsPlguin,Webpack构建失败 - webpack build failed because of uglifyJsPlguin
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM