441010741@qq.com
441010741@qq.com
  • 发布:2019-09-05 18:59
  • 更新:2020-01-17 10:53
  • 阅读:3354

uniapp 加载require('webpack')失败

分类:uni-app

uniapp项目里面增加vue.config.js文件

vue.config.js代码如下

const path = require('path')
const webpack = require('webpack')

module.exports = {

}

编译报错如下:
[HBuilder] 18:55:30.627 ERROR Error loading vue.config.js:
[HBuilder] 18:55:30.629 ERROR Error: Cannot find module 'webpack'
[HBuilder] 18:55:30.639 Error: Cannot find module 'webpack'
[HBuilder] 18:55:30.644 at Function.Module._resolveFilename (module.js:547:15)
[HBuilder] 18:55:30.646 at Function.Module._resolveFilename (D:\Works\HBuilderX\plugins\uniapp-cli\node_modules\module-alias\index.js:49:29)
[HBuilder] 18:55:30.660 at Function.Module._load (module.js:474:25)
[HBuilder] 18:55:30.661 at Module.require (module.js:596:17)
[HBuilder] 18:55:30.667 at require (internal/module.js:11:18)
[HBuilder] 18:55:30.668 at Object. (D:\My Documents\HBuilderProjects\demo3\vue.config.js:2:17)
[HBuilder] 18:55:30.675 at Module._compile (module.js:652:30)
[HBuilder] 18:55:30.677 at Object.Module._extensions..js (module.js:663:10)
[HBuilder] 18:55:30.682 at Module.load (module.js:565:32)
[HBuilder] 18:55:30.682 at tryModuleLoad (module.js:505:12)
[HBuilder] 18:55:30.688 at Function.Module._load (module.js:497:3)
[HBuilder] 18:55:30.688 at Module.require (module.js:596:17)
[HBuilder] 18:55:30.695 at require (internal/module.js:11:18)
[HBuilder] 18:55:30.696 at Service.loadUserOptions (D:\Works\HBuilderX\plugins\uniapp-cli\node_modules\@vue\cli-service\lib\Service.js:283:22)
[HBuilder] 18:55:30.705 at Service.init (D:\Works\HBuilderX\plugins\uniapp-cli\node_modules\@vue\cli-service\lib\Service.js:72:30)
[HBuilder] 18:55:30.706 at Service.run (D:\Works\HBuilderX\plugins\uniapp-cli\node_modules\@vue\cli-service\lib\Service.js:204:10)

2019-09-05 18:59 负责人:无 分享
已邀请:
18633753573@163.com

18633753573@163.com

作者解决了么,想请问如何解决的。我刚升级了 cli 遇到了同样的问题 。 QQ:1119094779。望作者回复,谢谢

哇哇哇哇

哇哇哇哇 - 前端工程师

一样遇到这个问题,作者解决了吗

菜鸡

菜鸡

你没npm install webpack的话,哪里有webpack给你require?
(记得install之前先npm init)

要回复问题请先登录注册