我正在尝试将我的nodejs express应用程序与Webpack捆绑在一起,我一直遇到相同的错误,将非常感谢您的帮助
节点版本 8.9.1
webpack版本 4.41.2
操作系统 Windows 10
我的项目结构
.
├── node_modules
├── package.json
├── README.md
├── src
│ ├── components
│ ├── index.js
|__ webpack-config.js
|
我的Webpack配置正在关注
var webpack = require('webpack');
import path from "path";
import nodeExternals from "webpack-node-externals";
module.exports = {
entry: {app:"./src/index.js"},
target: "node",
output: {
path: path.join(__dirname, 'webpack-build'),
filename: "bundle.js"
},
module:{
rules:[{
test: /\.(js)$/,
exclude: /(node_modules)/,
// flags to apply these rules, even if they are overridden (advanced option)
loader: "babel-loader",
// the loader which should be applied, it'll be resolved relative to the context
options: {
presets: ["es2015"]
},
}]
},
externals: [nodeExternals()]
};
我尝试过的事情
将webpack-node-externals添加到“外部”属性
尝试添加
解决:{ 根目录:[path.resolve(__ dirname,'src'),path.resolve(__ dirname,'node_modules')], 扩展名:['','.js'] };
我遇到错误