vue create -p dcloudio/uni-preset-vue my-project
npm run dev:h5
- 发布:2022-02-20 16:50
- 更新:2023-11-01 16:02
- 阅读:6798
【报Bug】vue create创建的项目webpack4报错TypeError: Cannot convert undefined or null to object
产品分类: uniapp/H5
PC开发环境操作系统: Windows
PC开发环境操作系统版本号: Windows10
HBuilderX类型: 正式
HBuilderX版本号: 3.3.11
浏览器平台: Chrome
浏览器版本: 94
项目创建方式: HBuilderX
操作步骤:
预期结果:
正常运行
正常运行
实际结果:
huimeng@0.1.0 dev:h5 C:\Users\hugetiny\Documents\HBuilderProjects\huimeng
cross-env NODE_ENV=development UNI_PLATFORM=h5 vue-cli-service uni-serve
请注意运行模式下,因日志输出、sourcemap以及未压缩源码等原因,性能和包体积,均不及发行模式。
INFO Starting development server...
ERROR TypeError: Cannot convert undefined or null to object
TypeError: Cannot convert undefined or null to object
at Function.assign (<anonymous>)
at C:\Users\hugetiny\Documents\HBuilderProjects\huimeng\node_modules\@dcloudio\vue-cli-plugin-uni\lib\chain-webpack.js:30:32
at Object.tap (C:\Users\hugetiny\Documents\HBuilderProjects\huimeng\node_modules\webpack-chain\src\Use.js:14:20)
at C:\Users\hugetiny\Documents\HBuilderProjects\huimeng\node_modules\@dcloudio\vue-cli-plugin-uni\lib\chain-webpack.js:30:10
at Array.forEach (<anonymous>)
at C:\Users\hugetiny\Documents\HBuilderProjects\huimeng\node_modules\@dcloudio\vue-cli-plugin-uni\lib\chain-webpack.js:25:17
at C:\Users\hugetiny\Documents\HBuilderProjects\huimeng\node_modules\@vue\cli-service\lib\Service.js:268:40
at Array.forEach (<anonymous>)
at Service.resolveChainableWebpackConfig (C:\Users\hugetiny\Documents\HBuilderProjects\huimeng\node_modules\@vue\cli-service\lib\Service.js:268:26)
at Service.resolveWebpackConfig (C:\Users\hugetiny\Documents\HBuilderProjects\huimeng\node_modules\@vue\cli-service\lib\Service.js:272:48)
at PluginAPI.resolveWebpackConfig (C:\Users\hugetiny\Documents\HBuilderProjects\huimeng\node_modules\@vue\cli-service\lib\PluginAPI.js:132:25)
at serve (C:\Users\hugetiny\Documents\HBuilderProjects\huimeng\node_modules\@dcloudio\vue-cli-plugin-uni\commands\serve.js:51:31)
at Service.run (C:\Users\hugetiny\Documents\HBuilderProjects\huimeng\node_modules\@vue\cli-service\lib\Service.js:262:12)
at processTicksAndRejections (internal/process/task_queues.js:97:5)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! huimeng@0.1.0 dev:h5: cross-env NODE_ENV=development UNI_PLATFORM=h5 vue-cli-service uni-serve
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the huimeng@0.1.0 dev:h5 script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\hugetiny\AppData\Roaming\npm-cache_logs\2022-02-20T08_19_32_872Z-debug.log
huimeng@0.1.0 dev:h5 C:\Users\hugetiny\Documents\HBuilderProjects\huimeng
cross-env NODE_ENV=development UNI_PLATFORM=h5 vue-cli-service uni-serve
请注意运行模式下,因日志输出、sourcemap以及未压缩源码等原因,性能和包体积,均不及发行模式。
INFO Starting development server...
ERROR TypeError: Cannot convert undefined or null to object
TypeError: Cannot convert undefined or null to object
at Function.assign (<anonymous>)
at C:\Users\hugetiny\Documents\HBuilderProjects\huimeng\node_modules\@dcloudio\vue-cli-plugin-uni\lib\chain-webpack.js:30:32
at Object.tap (C:\Users\hugetiny\Documents\HBuilderProjects\huimeng\node_modules\webpack-chain\src\Use.js:14:20)
at C:\Users\hugetiny\Documents\HBuilderProjects\huimeng\node_modules\@dcloudio\vue-cli-plugin-uni\lib\chain-webpack.js:30:10
at Array.forEach (<anonymous>)
at C:\Users\hugetiny\Documents\HBuilderProjects\huimeng\node_modules\@dcloudio\vue-cli-plugin-uni\lib\chain-webpack.js:25:17
at C:\Users\hugetiny\Documents\HBuilderProjects\huimeng\node_modules\@vue\cli-service\lib\Service.js:268:40
at Array.forEach (<anonymous>)
at Service.resolveChainableWebpackConfig (C:\Users\hugetiny\Documents\HBuilderProjects\huimeng\node_modules\@vue\cli-service\lib\Service.js:268:26)
at Service.resolveWebpackConfig (C:\Users\hugetiny\Documents\HBuilderProjects\huimeng\node_modules\@vue\cli-service\lib\Service.js:272:48)
at PluginAPI.resolveWebpackConfig (C:\Users\hugetiny\Documents\HBuilderProjects\huimeng\node_modules\@vue\cli-service\lib\PluginAPI.js:132:25)
at serve (C:\Users\hugetiny\Documents\HBuilderProjects\huimeng\node_modules\@dcloudio\vue-cli-plugin-uni\commands\serve.js:51:31)
at Service.run (C:\Users\hugetiny\Documents\HBuilderProjects\huimeng\node_modules\@vue\cli-service\lib\Service.js:262:12)
at processTicksAndRejections (internal/process/task_queues.js:97:5)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! huimeng@0.1.0 dev:h5: cross-env NODE_ENV=development UNI_PLATFORM=h5 vue-cli-service uni-serve
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the huimeng@0.1.0 dev:h5 script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\hugetiny\AppData\Roaming\npm-cache_logs\2022-02-20T08_19_32_872Z-debug.log
bug描述:
webpack4是官方推荐的。
webpack4之后,
npm run dev:h5
报错
huimeng@0.1.0 dev:h5 C:\Users\hugetiny\Documents\HBuilderProjects\huimeng
cross-env NODE_ENV=development UNI_PLATFORM=h5 vue-cli-service uni-serve
请注意运行模式下,因日志输出、sourcemap以及未压缩源码等原因,性能和包体积,均不及发行模式。
INFO Starting development server...
ERROR TypeError: Cannot convert undefined or null to object
TypeError: Cannot convert undefined or null to object
at Function.assign (<anonymous>)
at C:\Users\hugetiny\Documents\HBuilderProjects\huimeng\node_modules\@dcloudio\vue-cli-plugin-uni\lib\chain-webpack.js:30:32
at Object.tap (C:\Users\hugetiny\Documents\HBuilderProjects\huimeng\node_modules\webpack-chain\src\Use.js:14:20)
at C:\Users\hugetiny\Documents\HBuilderProjects\huimeng\node_modules\@dcloudio\vue-cli-plugin-uni\lib\chain-webpack.js:30:10
at Array.forEach (<anonymous>)
at C:\Users\hugetiny\Documents\HBuilderProjects\huimeng\node_modules\@dcloudio\vue-cli-plugin-uni\lib\chain-webpack.js:25:17
at C:\Users\hugetiny\Documents\HBuilderProjects\huimeng\node_modules\@vue\cli-service\lib\Service.js:268:40
at Array.forEach (<anonymous>)
at Service.resolveChainableWebpackConfig (C:\Users\hugetiny\Documents\HBuilderProjects\huimeng\node_modules\@vue\cli-service\lib\Service.js:268:26)
at Service.resolveWebpackConfig (C:\Users\hugetiny\Documents\HBuilderProjects\huimeng\node_modules\@vue\cli-service\lib\Service.js:272:48)
at PluginAPI.resolveWebpackConfig (C:\Users\hugetiny\Documents\HBuilderProjects\huimeng\node_modules\@vue\cli-service\lib\PluginAPI.js:132:25)
at serve (C:\Users\hugetiny\Documents\HBuilderProjects\huimeng\node_modules\@dcloudio\vue-cli-plugin-uni\commands\serve.js:51:31)
at Service.run (C:\Users\hugetiny\Documents\HBuilderProjects\huimeng\node_modules\@vue\cli-service\lib\Service.js:262:12)
at processTicksAndRejections (internal/process/task_queues.js:97:5)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! huimeng@0.1.0 dev:h5: cross-env NODE_ENV=development UNI_PLATFORM=h5 vue-cli-service uni-serve
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the huimeng@0.1.0 dev:h5 script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\hugetiny\AppData\Roaming\npm-cache_logs\2022-02-20T08_47_36_976Z-debug.log
我也出现同样的问题,通过uni-cli执行的以下几条命令(无其他任何命令):
vue create -p dcloudio/uni-preset-vue my-project
cd my-project
npm i webpack@4.29.5 --force
npm run build:mp-weixin
环境为Mac系统(实际上Ubuntu也测试了也一样),执行npm run build:mp-weixin时报错内容如下:
uniapp@0.1.0 build:mp-weixin
cross-env NODE_ENV=production UNI_PLATFORM=mp-weixin vue-cli-service uni-build小程序各家浏览器内核及自定义组件实现机制存在差异,可能存在样式布局兼容问题,参考:https://uniapp.dcloud.io/matter?id=mp
✔ 开始编译当前项目至 mp-weixin 平台...
ERROR TypeError: Cannot convert undefined or null to object
TypeError: Cannot convert undefined or null to object
at Function.assign (<anonymous>)
at /Users/galen/Project/dtalkMall/已上线商城/玉熙坊_6.7.0/DtalkMall/Client/test/uniapp/node_modules/@dcloudio/vue-cli-plugin-uni/lib/chain-webpack.js:30:32
at Object.tap (/Users/galen/Project/dtalkMall/已上线商城/玉熙坊_6.7.0/DtalkMall/Client/test/uniapp/node_modules/webpack-chain/src/Use.js:14:20)
at /Users/galen/Project/dtalkMall/已上线商城/玉熙坊_6.7.0/DtalkMall/Client/test/uniapp/node_modules/@dcloudio/vue-cli-plugin-uni/lib/chain-webpack.js:30:10
at Array.forEach (<anonymous>)
at /Users/galen/Project/dtalkMall/已上线商城/玉熙坊_6.7.0/DtalkMall/Client/test/uniapp/node_modules/@dcloudio/vue-cli-plugin-uni/lib/chain-webpack.js:25:17
at /Users/galen/Project/dtalkMall/已上线商城/玉熙坊_6.7.0/DtalkMall/Client/test/uniapp/node_modules/@vue/cli-service/lib/Service.js:268:40
at Array.forEach (<anonymous>)
at Service.resolveChainableWebpackConfig (/Users/galen/Project/dtalkMall/已上线商城/玉熙坊_6.7.0/DtalkMall/Client/test/uniapp/node_modules/@vue/cli-service/lib/Service.js:268:26)
at PluginAPI.resolveChainableWebpackConfig (/Users/galen/Project/dtalkMall/已上线商城/玉熙坊_6.7.0/DtalkMall/Client/test/uniapp/node_modules/@vue/cli-service/lib/PluginAPI.js:145:25)
at module.exports (/Users/galen/Project/dtalkMall/已上线商城/玉熙坊_6.7.0/DtalkMall/Client/test/uniapp/node_modules/@vue/cli-service/lib/commands/build/resolveAppConfig.js:9:22)
at getWebpackConfig (/Users/galen/Project/dtalkMall/已上线商城/玉熙坊_6.7.0/DtalkMall/Client/test/uniapp/node_modules/@dcloudio/vue-cli-plugin-uni/commands/build.js:84:88)
at getWebpackConfigs (/Users/galen/Project/dtalkMall/已上线商城/玉熙坊_6.7.0/DtalkMall/Client/test/uniapp/node_modules/@dcloudio/vue-cli-plugin-uni/commands/build.js:113:13)
at build (/Users/galen/Project/dtalkMall/已上线商城/玉熙坊_6.7.0/DtalkMall/Client/test/uniapp/node_modules/@dcloudio/vue-cli-plugin-uni/commands/build.js:153:26)
at /Users/galen/Project/dtalkMall/已上线商城/玉熙坊_6.7.0/DtalkMall/Client/test/uniapp/node_modules/@dcloudio/vue-cli-plugin-uni/commands/build.js:75:11
at Service.run (/Users/galen/Project/dtalkMall/已上线商城/玉熙坊_6.7.0/DtalkMall/Client/test/uniapp/node_modules/@vue/cli-service/lib/Service.js:262:12)
如果不想卸载vue-cli后再重装,可以使用npx
npx @vue/cli@4.5.14 create -p dcloudio/uni-preset-vue my-uniapp
参考:https://stackoverflow.com/questions/59660391/is-there-any-npx-create-react-app-equivalent-for-vue-cli
软猫引擎钟某
坑已爬,问题已解决。uni-cli官方文档不严谨导致的。
由于执行npm install -g @vue/cli 默认安装的是最新版本,刚好当前vue-cli版本为5.x
但uni-cli仅支持vue-cli 4.x版本,将版本降级就行了。
解决方案如下:
移除原vue-cli
npm remove -g @vue/cli
重新安装vue-cli 4.x版本
npm install -g @vue/cli@4.5.14
然后重新拉一遍即可:
vue create -p dcloudio/uni-preset-vue my-project
cd my-project
npm run build:mp-weixin
2022-03-04 01:34
1***@qq.com
感谢,问题已解决。
2022-04-27 14:42