问答详情
源自:1-2 Webpack 安装和命令行

webpack hello.js hello.bundle.js 报错


$ webpack hello.js hello.bundle.js

C:\Users\yu\AppData\Roaming\npm\node_modules\webpack-cli\bin\cli.js:244

                                throw err;

                                ^


TypeError: Cannot read property 'length' of undefined

    at processConfiguredOptions (C:\Users\yu\AppData\Roaming\npm\node_modules\webpack-cli\bin\convert-argv.js:160:44)

    at module.exports (C:\Users\yu\AppData\Roaming\npm\node_modules\webpack-cli\bin\convert-argv.js:148:10)

    at yargs.parse (C:\Users\yu\AppData\Roaming\npm\node_modules\webpack-cli\bin\cli.js:241:39)

    at Object.parse (C:\Users\yu\AppData\Roaming\npm\node_modules\webpack-cli\node_modules\_yargs@11.1.0@yargs\yargs.js:552:18)

    at C:\Users\yu\AppData\Roaming\npm\node_modules\webpack-cli\bin\cli.js:219:8

    at Object.<anonymous> (C:\Users\yu\AppData\Roaming\npm\node_modules\webpack-cli\bin\cli.js:530:3)

    at Module._compile (internal/modules/cjs/loader.js:778:30)

    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)

    at Module.load (internal/modules/cjs/loader.js:653:32)

    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)

    at Function.Module._load (internal/modules/cjs/loader.js:585:3)

    at Module.require (internal/modules/cjs/loader.js:692:17)

    at require (internal/modules/cjs/helpers.js:25:18)

    at runCli (C:\Users\yu\AppData\Roaming\npm\node_modules\webpack\bin\webpack.js:54:2)

    at Object.<anonymous> (C:\Users\yu\AppData\Roaming\npm\node_modules\webpack\bin\webpack.js:147:2)

    at Module._compile (internal/modules/cjs/loader.js:778:30)

    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)

    at Module.load (internal/modules/cjs/loader.js:653:32)

    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)

    at Function.Module._load (internal/modules/cjs/loader.js:585:3)

    at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)

    at startup (internal/bootstrap/node.js:283:19)

    at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)


提问者:慕容2428546 2021-09-28 00:04

个回答

  • weixin_慕斯1009030
    2021-11-16 22:18:34

     webpack ./hello.js --output-path ./ --output-filename bundle.js --mode development

    搜索

    复制

  • 慕侠253528
    2021-10-23 15:17:40

    webpack新版本不支持,建议在目录下加个webpack.config.js文件
    const path = require('path');module.exports = {  entry: './hello.js',  mode: 'development',  output: {    filename: 'hello.bundle.js',    path: path.resolve(__dirname)  },};
    
    然后运行 webpack就可以了