使用webpack命令打包时,报错TypeError: Cannot read property 'presetToOptions' of undefined的解决办法
程序员文章站
2022-03-07 08:51:47
我只安装了webpack,没有安装webpack cli,第一次输入webpack打包时,提示 输入yes后报错 解决办法:输入命令npm install webpack cli g全局安装一下webpack cli 再次运行webpack命令打包,出现新错误 解决办法:根据错误提示信息,打开nod ......
我只安装了webpack,没有安装webpack-cli,第一次输入webpack打包时,提示
one cli for webpack must be installed. these are recommended choices, delivered as separate packages: - webpack-cli (https://github.com/webpack/webpack-cli) the original webpack full-featured cli. we will use "npm" to install the cli via "npm install -d". do you want to install 'webpack-cli' (yes/no):
输入yes后报错
error: cannot find module 'webpack-cli' require stack: - c:\users\administrator\appdata\roaming\npm\node_modules\webpack\bin\webpack.js at function.module._resolvefilename (internal/modules/cjs/loader.js:772:15) at function.module._load (internal/modules/cjs/loader.js:677:27) at module.require (internal/modules/cjs/loader.js:830:19) at require (internal/modules/cjs/helpers.js:68:18) at c:\users\administrator\appdata\roaming\npm\node_modules\webpack\bin\webpack.js:143:5 at processticksandrejections (internal/process/task_queues.js:93:5) { code: 'module_not_found', requirestack: [ 'c:\\users\\administrator\\appdata\\roaming\\npm\\node_modules\\webpack\\bin\\webpack.js' ] }
解决办法:输入命令npm install webpack-cli -g全局安装一下webpack-cli
再次运行webpack命令打包,出现新错误
f:\myweb\alice\vue\vue-cms\node_modules\webpack-cli\bin\cli.js:137 const statspresettooptions = require("webpack").stats.presettooptions; ^ typeerror: cannot read property 'presettooptions' of undefined at processoptions (f:\myweb\alice\vue\vue-cms\node_modules\webpack-cli\bin\cli.js:137:57) at f:\myweb\alice\vue\vue-cms\node_modules\webpack-cli\bin\cli.js:364:3 at object.parse (f:\myweb\alice\vue\vue-cms\node_modules\webpack-cli\node_modules\yargs\yargs.js:567:18) at f:\myweb\alice\vue\vue-cms\node_modules\webpack-cli\bin\cli.js:49:8 at object.<anonymous> (f:\myweb\alice\vue\vue-cms\node_modules\webpack-cli\bin\cli.js:366:3) at module._compile (internal/modules/cjs/loader.js:936:30) at object.module._extensions..js (internal/modules/cjs/loader.js:947:10) at module.load (internal/modules/cjs/loader.js:790:32) at function.module._load (internal/modules/cjs/loader.js:703:12) at module.require (internal/modules/cjs/loader.js:830:19) at require (internal/modules/cjs/helpers.js:68:18) at module.exports (c:\users\administrator\appdata\roaming\npm\node_modules\webpack-cli\node_modules\import-local\index.js:16:66) at c:\users\administrator\appdata\roaming\npm\node_modules\webpack-cli\bin\cli.js:15:6 at object.<anonymous> (c:\users\administrator\appdata\roaming\npm\node_modules\webpack-cli\bin\cli.js:366:3) at module._compile (internal/modules/cjs/loader.js:936:30) at object.module._extensions..js (internal/modules/cjs/loader.js:947:10) at module.load (internal/modules/cjs/loader.js:790:32) at function.module._load (internal/modules/cjs/loader.js:703:12) at module.require (internal/modules/cjs/loader.js:830:19) at require (internal/modules/cjs/helpers.js:68:18) at object.<anonymous> (c:\users\administrator\appdata\roaming\npm\node_modules\webpack\bin\webpack.js:156:2) at module._compile (internal/modules/cjs/loader.js:936:30) at object.module._extensions..js (internal/modules/cjs/loader.js:947:10) at module.load (internal/modules/cjs/loader.js:790:32) at function.module._load (internal/modules/cjs/loader.js:703:12) at function.module.runmain (internal/modules/cjs/loader.js:999:10) at internal/main/run_main_module.js:17:11
解决办法:根据错误提示信息,打开node_modules\webpack-cli\bin\cli.js,第137行,把const statspresettooptions = require("webpack").stats.presettooptions;中间stats下标的这个.删掉。
保存后再次运行webpack就成功了!
上一篇: python使用socket创建tcp服务器和客户端
下一篇: Python学习笔记之测试函数