小菜鸟一枚,最近正在学习webpack打包nodejs的项目,但是打包总是不成功,报错最多的就是找不到文件,但是我用npm install 明明安上了,请问有谁遇到过这种问题吗?请教。。
报错信息:
文件的具体配置
package.json
{
"name": "dome8_express",
"version": "0.0.1",
"main": "app.js",
"author": "ljb",
"license": "ISC",
"description": "nodeJS --express --webpack",
"scripts": {
"start": "webpack",
"server": "webpack-dev-server --open",
"build": "webpack --mode production",
"dev": "webpack --mode development",
"test": "echo \"Error: no test specified\" && exit 1"
},
"dependencies": {
"babel-loader": "^8.0.4",
"body-parser": "^1.18.3",
"cookie-parser": "^1.4.3",
"debug": "^4.1.0",
"ejs": "^2.6.1",
"errorhandler": "^1.5.0",
"eventproxy": "*",
"express": "^4.16.4",
"express-session": "^1.15.6",
"fs": "*",
"html": "*",
"method-override": "^3.0.0",
"morgan": "^1.9.1",
"mysql": "^2.16.0",
"node-uuid": "^1.4.8",
"serve-favicon": "^2.5.0",
"uglifyjs-webpack-plugin": "^2.0.1",
"webpack-cli": "^3.1.2"
},
"devDependencies": {
"css-loader": "^1.0.0",
"html-webpack-plugin": "^3.2.0",
"style-loader": "^0.23.1",
"webpack": "^4.20.2",
"webpack-dev-server": "3.1.9"
}
}
webpack.config.js
var path = require("path");
var webpack = require('webpack'); //访问内置的插件
var HtmlWebpackPlugin = require('html-webpack-plugin'); //通过 npm 安装
var uglifyjsPlugin = require('uglifyjs-webpack-plugin');
module.exports = {
mode: 'production',
devtool: 'eval-source-map', //打包方式
// webpack 配置 :"webpack": "^4.20.2",
entry:'./app.js', //入口文件
output: { //出口文件
path: path.resolve(__dirname, "routes"),
filename: "main.js"
},
//服务器配置:"webpack-dev-server": "3.1.9"
devServer: {
port:'8080', //端口
contentBase: "/public", //本地服务器所加载的页面所在的目录
historyApiFallback: true, //不跳转
inline: true //实时刷新
},
//module
module:{
rules:[
{test:/\.css$/, use:'css-loader'},
{test:/\.ts$/, use:'ts-loader'},
//{test:/\.(js|jsx)$/,use: 'babel-loader'}
]
},
//html webpack plugin
plugins:[
new HtmlWebpackPlugin({
template:'./public/views/login.html'
})
],
//压缩js
optimization: {
minimizer: [
new uglifyjsPlugin({ uglifyOptions: {compress: false } })
]
},
};
## 使用webpack打包nodejs项目报错:ERROR in ./node_modules/mysql/lib/Connection.js
Module not found: Error: Can't resolve 'net' in 'E:\NodeJs\workSpace\dome8_express\node_modules\mysql\lib'