npx webpack 报错我实在找不出原因

npx webpack 报错我实在找不出原因

http://img1.sycdn.imooc.com//climg/5e07924409ca17d711340436.jpg

const path = require('path')
const nodeExternals = require('webpack-node-externals')
const { CleanWebpackPlugin } = require('clean-webpack-plugin')
debugger
const webpackconfig = {
    target: 'node',
    mode: 'development',
    entry: {
        server: path.join(__dirname, 'src/index.js')
    },
    output: {
        filename: '[name].bundle.js',
        path: path.join(__dirname, './dist')
    },
    devtool: 'eval-source-map',
    module: {
        rules: [
            {
                test: /\.(js|jsx)$/,
                use: {
                    loader: 'babel-loader'
                },
                exclude: [path.join(__dirname, '/node_modules')]
            }
        ]
    },
    externals: [nodeExternals()],
    plugins: [
        new CleanWebpackPlugin()
    ],
    node: {
        console: true,
        global: true,
        process: true,
        Buffer: true,
        __filename: true,
        __dirname: true,
        setImmediate: true,
        path: true
    }
}


console.log(webpackconfig)
const a = 0
module.exports = webpackconfig


正在回答 回答被采纳积分+1

登陆购买课程后可参与讨论,去登陆

1回答
Brian 2019-12-29 22:31:16

http://img1.sycdn.imooc.com//climg/5e08b82a08f9636414520722.jpg

我跟你一样的配置,没有打包出现错误:

package.json

{
"name": "webpack-demo",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"@babel/core": "^7.7.7",
"babel-loader": "^8.0.6",
"clean-webpack-plugin": "^3.0.0",
"webpack": "^4.41.5",
"webpack-cli": "^3.3.10",
"webpack-node-externals": "^1.7.2"
}
}

webpack.config.js

const path = require('path')
const nodeExternals = require('webpack-node-externals')
const { CleanWebpackPlugin } = require('clean-webpack-plugin')
const webpackconfig = {
target: 'node',
mode: 'development',
entry: {
server: path.join(__dirname, 'src/index.js')
},
output: {
filename: '[name].bundle.js',
path: path.join(__dirname, './dist')
},
devtool: 'eval-source-map',
module: {
rules: [
{
test: /\.(js|jsx)$/,
use: {
loader: 'babel-loader'
},
exclude: [path.join(__dirname, '/node_modules')]
}
]
},
externals: [nodeExternals()],
plugins: [
new CleanWebpackPlugin()
],
node: {
console: true,
global: true,
process: true,
Buffer: true,
__filename: true,
__dirname: true,
setImmediate: true,
path: true
}
}

module.exports = webpackconfig


node, nvm版本:

➜ node -v

v12.13.1

➜ nvm --version

0.35.1


  • 提问者 慕UI653502 #1
    我的是Windows系统,你的是linux,唉还是报错
    2019-12-30 09:35:32
  • 提问者 慕UI653502 #2
    话说你们的教学示例,不在Windows环境下调试一下的吗?
    2019-12-30 09:36:54
  • 慕后端3518689 回复 提问者 慕UI653502 #3
    看你的报错好像是target参数错误,我是Windows系统没有报错
    2019-12-30 17:00:02
问题已解决,确定采纳
还有疑问,暂不采纳

恭喜解决一个难题,获得1积分~

来为老师/同学的回答评分吧

0 星
请稍等 ...
意见反馈 帮助中心 APP下载
官方微信

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师