举头望明月
举头望明月
  • 发布:2023-09-20 14:28
  • 更新:2023-12-19 15:02
  • 阅读:2657

【已解决】VUE3项目,添加vite.config.js后,各种报错

分类:uni-app

产品分类: uniapp/小程序/微信

PC开发环境操作系统: Mac

PC开发环境操作系统版本号: 13.5.2

HBuilderX类型: 正式

HBuilderX版本号: 3.8.12

第三方开发者工具版本号: 1.06.2308310

基础库版本号: 3.0.0

项目创建方式: HBuilderX

示例代码:

import { defineConfig } from 'vite';
import uni from '@dcloudio/vite-plugin-uni';

export default defineConfig({
plugins: [uni()],
});

操作步骤:

第一步安装了 npm i @dcloudio/vite-plugin-uni,然后新建vite.config.js,代码如上,然后报错:Error: Cannot find module '../../../uni-cli-shared/dist'。

14:13:57.166 failed to load config from /Users/jycloud/Documents/项目/乐享大东/lxdd-member/vite.config.js
14:13:57.176 error during build:
14:13:57.177 Error: Cannot find module '../../../uni-cli-shared/dist'
14:13:57.189 Require stack:
14:13:57.189 - /Users/jycloud/Documents/项目/乐享大东/lxdd-member/node_modules/@dcloudio/vite-plugin-uni/dist/configResolved/config.js
14:13:57.214 - /Users/jycloud/Documents/项目/乐享大东/lxdd-member/node_modules/@dcloudio/vite-plugin-uni/dist/configResolved/index.js
14:13:57.215 - /Users/jycloud/Documents/项目/乐享大东/lxdd-member/node_modules/@dcloudio/vite-plugin-uni/dist/index.js
14:13:57.228 - /Users/jycloud/Documents/项目/乐享大东/lxdd-member/vite.config.js
14:13:57.241 - /Applications/HBuilderX.app/Contents/HBuilderX/plugins/uniapp-cli-vite/node_modules/vite/dist/node/chunks/dep-79892de8.js
14:13:57.244 at Function.Module._resolveFilename (node:internal/modules/cjs/loader:956:15)
14:13:57.257 at Function.Module._resolveFilename (/Applications/HBuilderX.app/Contents/HBuilderX/plugins/uniapp-cli-vite/node_modules/module-alias/index.js:49:29)
14:13:57.271 at Function.Module._load (node:internal/modules/cjs/loader:804:27)
14:13:57.284 at Module.require (node:internal/modules/cjs/loader:1028:19)
14:13:57.285 at require (node:internal/modules/cjs/helpers:102:18)
14:13:57.296 at Object.<anonymous> (/Users/jycloud/Documents/项目/乐享大东/lxdd-member/node_modules/@dcloudio/vite-plugin-uni/dist/configResolved/config.js:4:16)
14:13:57.296 at Module._compile (node:internal/modules/cjs/loader:1126:14)
14:13:57.309 at Module._extensions..js (node:internal/modules/cjs/loader:1180:10)
14:13:57.322 at Object._require.extensions.<computed> [as .js] (file:///Applications/HBuilderX.app/Contents/HBuilderX/plugins/uniapp-cli-vite/node_modules/vite/dist/node/chunks/dep-79892de8.js:63989:17)
14:13:57.323 at Module.load (node:internal/modules/cjs/loader:1004:32)

第二步又安装了 npm i @dcloudio/uni-cli-shared,然后报错:Error: Cannot find module '@dcloudio/uni-cli-i18n'。

14:22:58.964 failed to load config from /Users/jycloud/Documents/项目/乐享大东/lxdd-member/vite.config.js
14:22:58.965 error during build:
14:22:58.982 Error: Cannot find module '@dcloudio/uni-cli-i18n'
14:22:58.997 Require stack:
14:22:59.000 - /Users/jycloud/Documents/项目/乐享大东/lxdd-member/node_modules/@dcloudio/uni-cli-shared/lib/json.js
14:22:59.015 - /Users/jycloud/Documents/项目/乐享大东/lxdd-member/node_modules/@dcloudio/uni-cli-shared/lib/index.js
14:22:59.016 - /Users/jycloud/Documents/项目/乐享大东/lxdd-member/node_modules/@dcloudio/vite-plugin-uni/dist/config/index.js
14:22:59.031 - /Users/jycloud/Documents/项目/乐享大东/lxdd-member/node_modules/@dcloudio/vite-plugin-uni/dist/index.js
14:22:59.032 - /Users/jycloud/Documents/项目/乐享大东/lxdd-member/vite.config.js
14:22:59.047 - /Applications/HBuilderX.app/Contents/HBuilderX/plugins/uniapp-cli-vite/node_modules/vite/dist/node/chunks/dep-79892de8.js
14:22:59.049 at Function.Module._resolveFilename (node:internal/modules/cjs/loader:956:15)
14:22:59.065 at Function.Module._resolveFilename (/Applications/HBuilderX.app/Contents/HBuilderX/plugins/uniapp-cli-vite/node_modules/module-alias/index.js:49:29)
14:22:59.066 at Function.Module._load (node:internal/modules/cjs/loader:804:27)
14:22:59.083 at Module.require (node:internal/modules/cjs/loader:1028:19)
14:22:59.084 at require (node:internal/modules/cjs/helpers:102:18)
14:22:59.105 at Object.<anonymous> (/Users/jycloud/Documents/项目/乐享大东/lxdd-member/node_modules/@dcloudio/uni-cli-shared/lib/json.js:4:17)
14:22:59.109 at Module._compile (node:internal/modules/cjs/loader:1126:14)
14:22:59.128 at Module._extensions..js (node:internal/modules/cjs/loader:1180:10)
14:22:59.131 at Object._require.extensions.<computed> [as .js] (file:///Applications/HBuilderX.app/Contents/HBuilderX/plugins/uniapp-cli-vite/node_modules/vite/dist/node/chunks/dep-79892de8.js:63989:17)
14:22:59.153 at Module.load (node:internal/modules/cjs/loader:1004:32)

第三步又安装了 npm i @dcloudio/uni-cli-i18n,然后报错:Error: Cannot find module 'webpack'。

14:25:29.526 failed to load config from /Users/jycloud/Documents/项目/乐享大东/lxdd-member/vite.config.js
14:25:29.537 error during build:
14:25:29.538 Error: Cannot find module 'webpack'
14:25:29.549 Require stack:
14:25:29.550 - /Users/jycloud/Documents/项目/乐享大东/lxdd-member/node_modules/@dcloudio/uni-cli-shared/lib/util.js
14:25:29.562 - /Users/jycloud/Documents/项目/乐享大东/lxdd-member/node_modules/@dcloudio/uni-cli-shared/lib/manifest.js
14:25:29.576 - /Users/jycloud/Documents/项目/乐享大东/lxdd-member/node_modules/@dcloudio/uni-cli-shared/lib/index.js
14:25:29.576 - /Users/jycloud/Documents/项目/乐享大东/lxdd-member/node_modules/@dcloudio/vite-plugin-uni/dist/config/index.js
14:25:29.601 - /Users/jycloud/Documents/项目/乐享大东/lxdd-member/node_modules/@dcloudio/vite-plugin-uni/dist/index.js
14:25:29.601 - /Users/jycloud/Documents/项目/乐享大东/lxdd-member/vite.config.js
14:25:29.616 - /Applications/HBuilderX.app/Contents/HBuilderX/plugins/uniapp-cli-vite/node_modules/vite/dist/node/chunks/dep-79892de8.js
14:25:29.617 at Function.Module._resolveFilename (node:internal/modules/cjs/loader:956:15)
14:25:29.630 at Function.Module._resolveFilename (/Applications/HBuilderX.app/Contents/HBuilderX/plugins/uniapp-cli-vite/node_modules/module-alias/index.js:49:29)
14:25:29.631 at Function.Module._load (node:internal/modules/cjs/loader:804:27)
14:25:29.646 at Module.require (node:internal/modules/cjs/loader:1028:19)
14:25:29.646 at require (node:internal/modules/cjs/helpers:102:18)
14:25:29.663 at Object.<anonymous> (/Users/jycloud/Documents/项目/乐享大东/lxdd-member/node_modules/@dcloudio/uni-cli-shared/lib/util.js:7:17)
14:25:29.663 at Module._compile (node:internal/modules/cjs/loader:1126:14)
14:25:29.680 at Module._extensions..js (node:internal/modules/cjs/loader:1180:10)
14:25:29.680 at Object._require.extensions.<computed> [as .js] (file:///Applications/HBuilderX.app/Contents/HBuilderX/plugins/uniapp-cli-vite/node_modules/vite/dist/node/chunks/dep-79892de8.js:63989:17)
14:25:29.697 at Module.load (node:internal/modules/cjs/loader:1004:32)

第四步又安装了 npm i webpack,然后报错:Error: Cannot find module 'webpack'。

14:27:06.546 failed to load config from /Users/jycloud/Documents/项目/乐享大东/lxdd-member/vite.config.js
14:27:06.556 error during build:
14:27:06.557 TypeError: Cannot read properties of undefined (reading 'options')
14:27:06.570 at Object.<anonymous> (/Users/jycloud/Documents/项目/乐享大东/lxdd-member/node_modules/@dcloudio/uni-cli-shared/lib/platform.js:47:43)
14:27:06.571 at Module._compile (node:internal/modules/cjs/loader:1126:14)
14:27:06.586 at Module._extensions..js (node:internal/modules/cjs/loader:1180:10)
14:27:06.603 at Object._require.extensions.<computed> [as .js] (file:///Applications/HBuilderX.app/Contents/HBuilderX/plugins/uniapp-cli-vite/node_modules/vite/dist/node/chunks/dep-79892de8.js:63989:17)
14:27:06.605 at Module.load (node:internal/modules/cjs/loader:1004:32)
14:27:06.619 at Function.Module._load (node:internal/modules/cjs/loader:839:12)
14:27:06.619 at Module.require (node:internal/modules/cjs/loader:1028:19)
14:27:06.638 at require (node:internal/modules/cjs/helpers:102:18)
14:27:06.639 at Object.<anonymous> (/Users/jycloud/Documents/项目/乐享大东/lxdd-member/node_modules/@dcloudio/uni-cli-shared/lib/index.js:67:5)
14:27:06.655 at Module._compile (node:internal/modules/cjs/loader:1126:14)

预期结果:

本来是要配置小程序加固那个配置文件,自动打进包里的

实际结果:

本来是要配置小程序加固那个配置文件,自动打进包里的

bug描述:

VUE3项目,node版本是你18.17.1,添加vite.config.js后,项目无法启动,各种报错

第一步安装了 npm i @dcloudio/vite-plugin-uni,然后新建vite.config.js,代码如上,然后报错:Error: Cannot find module '../../../uni-cli-shared/dist'。

14:13:57.166 failed to load config from /Users/jycloud/Documents/项目/乐享大东/lxdd-member/vite.config.js
14:13:57.176 error during build:
14:13:57.177 Error: Cannot find module '../../../uni-cli-shared/dist'
14:13:57.189 Require stack:
14:13:57.189 - /Users/jycloud/Documents/项目/乐享大东/lxdd-member/node_modules/@dcloudio/vite-plugin-uni/dist/configResolved/config.js
14:13:57.214 - /Users/jycloud/Documents/项目/乐享大东/lxdd-member/node_modules/@dcloudio/vite-plugin-uni/dist/configResolved/index.js
14:13:57.215 - /Users/jycloud/Documents/项目/乐享大东/lxdd-member/node_modules/@dcloudio/vite-plugin-uni/dist/index.js
14:13:57.228 - /Users/jycloud/Documents/项目/乐享大东/lxdd-member/vite.config.js
14:13:57.241 - /Applications/HBuilderX.app/Contents/HBuilderX/plugins/uniapp-cli-vite/node_modules/vite/dist/node/chunks/dep-79892de8.js
14:13:57.244 at Function.Module._resolveFilename (node:internal/modules/cjs/loader:956:15)
14:13:57.257 at Function.Module._resolveFilename (/Applications/HBuilderX.app/Contents/HBuilderX/plugins/uniapp-cli-vite/node_modules/module-alias/index.js:49:29)
14:13:57.271 at Function.Module._load (node:internal/modules/cjs/loader:804:27)
14:13:57.284 at Module.require (node:internal/modules/cjs/loader:1028:19)
14:13:57.285 at require (node:internal/modules/cjs/helpers:102:18)
14:13:57.296 at Object.<anonymous> (/Users/jycloud/Documents/项目/乐享大东/lxdd-member/node_modules/@dcloudio/vite-plugin-uni/dist/configResolved/config.js:4:16)
14:13:57.296 at Module._compile (node:internal/modules/cjs/loader:1126:14)
14:13:57.309 at Module._extensions..js (node:internal/modules/cjs/loader:1180:10)
14:13:57.322 at Object._require.extensions.<computed> [as .js] (file:///Applications/HBuilderX.app/Contents/HBuilderX/plugins/uniapp-cli-vite/node_modules/vite/dist/node/chunks/dep-79892de8.js:63989:17)
14:13:57.323 at Module.load (node:internal/modules/cjs/loader:1004:32)

第二步又安装了 npm i @dcloudio/uni-cli-shared,然后报错:Error: Cannot find module '@dcloudio/uni-cli-i18n'。

14:22:58.964 failed to load config from /Users/jycloud/Documents/项目/乐享大东/lxdd-member/vite.config.js
14:22:58.965 error during build:
14:22:58.982 Error: Cannot find module '@dcloudio/uni-cli-i18n'
14:22:58.997 Require stack:
14:22:59.000 - /Users/jycloud/Documents/项目/乐享大东/lxdd-member/node_modules/@dcloudio/uni-cli-shared/lib/json.js
14:22:59.015 - /Users/jycloud/Documents/项目/乐享大东/lxdd-member/node_modules/@dcloudio/uni-cli-shared/lib/index.js
14:22:59.016 - /Users/jycloud/Documents/项目/乐享大东/lxdd-member/node_modules/@dcloudio/vite-plugin-uni/dist/config/index.js
14:22:59.031 - /Users/jycloud/Documents/项目/乐享大东/lxdd-member/node_modules/@dcloudio/vite-plugin-uni/dist/index.js
14:22:59.032 - /Users/jycloud/Documents/项目/乐享大东/lxdd-member/vite.config.js
14:22:59.047 - /Applications/HBuilderX.app/Contents/HBuilderX/plugins/uniapp-cli-vite/node_modules/vite/dist/node/chunks/dep-79892de8.js
14:22:59.049 at Function.Module._resolveFilename (node:internal/modules/cjs/loader:956:15)
14:22:59.065 at Function.Module._resolveFilename (/Applications/HBuilderX.app/Contents/HBuilderX/plugins/uniapp-cli-vite/node_modules/module-alias/index.js:49:29)
14:22:59.066 at Function.Module._load (node:internal/modules/cjs/loader:804:27)
14:22:59.083 at Module.require (node:internal/modules/cjs/loader:1028:19)
14:22:59.084 at require (node:internal/modules/cjs/helpers:102:18)
14:22:59.105 at Object.<anonymous> (/Users/jycloud/Documents/项目/乐享大东/lxdd-member/node_modules/@dcloudio/uni-cli-shared/lib/json.js:4:17)
14:22:59.109 at Module._compile (node:internal/modules/cjs/loader:1126:14)
14:22:59.128 at Module._extensions..js (node:internal/modules/cjs/loader:1180:10)
14:22:59.131 at Object._require.extensions.<computed> [as .js] (file:///Applications/HBuilderX.app/Contents/HBuilderX/plugins/uniapp-cli-vite/node_modules/vite/dist/node/chunks/dep-79892de8.js:63989:17)
14:22:59.153 at Module.load (node:internal/modules/cjs/loader:1004:32)

第三步又安装了 npm i @dcloudio/uni-cli-i18n,然后报错:Error: Cannot find module 'webpack'。

14:25:29.526 failed to load config from /Users/jycloud/Documents/项目/乐享大东/lxdd-member/vite.config.js
14:25:29.537 error during build:
14:25:29.538 Error: Cannot find module 'webpack'
14:25:29.549 Require stack:
14:25:29.550 - /Users/jycloud/Documents/项目/乐享大东/lxdd-member/node_modules/@dcloudio/uni-cli-shared/lib/util.js
14:25:29.562 - /Users/jycloud/Documents/项目/乐享大东/lxdd-member/node_modules/@dcloudio/uni-cli-shared/lib/manifest.js
14:25:29.576 - /Users/jycloud/Documents/项目/乐享大东/lxdd-member/node_modules/@dcloudio/uni-cli-shared/lib/index.js
14:25:29.576 - /Users/jycloud/Documents/项目/乐享大东/lxdd-member/node_modules/@dcloudio/vite-plugin-uni/dist/config/index.js
14:25:29.601 - /Users/jycloud/Documents/项目/乐享大东/lxdd-member/node_modules/@dcloudio/vite-plugin-uni/dist/index.js
14:25:29.601 - /Users/jycloud/Documents/项目/乐享大东/lxdd-member/vite.config.js
14:25:29.616 - /Applications/HBuilderX.app/Contents/HBuilderX/plugins/uniapp-cli-vite/node_modules/vite/dist/node/chunks/dep-79892de8.js
14:25:29.617 at Function.Module._resolveFilename (node:internal/modules/cjs/loader:956:15)
14:25:29.630 at Function.Module._resolveFilename (/Applications/HBuilderX.app/Contents/HBuilderX/plugins/uniapp-cli-vite/node_modules/module-alias/index.js:49:29)
14:25:29.631 at Function.Module._load (node:internal/modules/cjs/loader:804:27)
14:25:29.646 at Module.require (node:internal/modules/cjs/loader:1028:19)
14:25:29.646 at require (node:internal/modules/cjs/helpers:102:18)
14:25:29.663 at Object.<anonymous> (/Users/jycloud/Documents/项目/乐享大东/lxdd-member/node_modules/@dcloudio/uni-cli-shared/lib/util.js:7:17)
14:25:29.663 at Module._compile (node:internal/modules/cjs/loader:1126:14)
14:25:29.680 at Module._extensions..js (node:internal/modules/cjs/loader:1180:10)
14:25:29.680 at Object._require.extensions.<computed> [as .js] (file:///Applications/HBuilderX.app/Contents/HBuilderX/plugins/uniapp-cli-vite/node_modules/vite/dist/node/chunks/dep-79892de8.js:63989:17)
14:25:29.697 at Module.load (node:internal/modules/cjs/loader:1004:32)

第四步又安装了 npm i webpack,然后报错:Error: Cannot find module 'webpack'。

14:27:06.546 failed to load config from /Users/jycloud/Documents/项目/乐享大东/lxdd-member/vite.config.js
14:27:06.556 error during build:
14:27:06.557 TypeError: Cannot read properties of undefined (reading 'options')
14:27:06.570 at Object.<anonymous> (/Users/jycloud/Documents/项目/乐享大东/lxdd-member/node_modules/@dcloudio/uni-cli-shared/lib/platform.js:47:43)
14:27:06.571 at Module._compile (node:internal/modules/cjs/loader:1126:14)
14:27:06.586 at Module._extensions..js (node:internal/modules/cjs/loader:1180:10)
14:27:06.603 at Object._require.extensions.<computed> [as .js] (file:///Applications/HBuilderX.app/Contents/HBuilderX/plugins/uniapp-cli-vite/node_modules/vite/dist/node/chunks/dep-79892de8.js:63989:17)
14:27:06.605 at Module.load (node:internal/modules/cjs/loader:1004:32)
14:27:06.619 at Function.Module._load (node:internal/modules/cjs/loader:839:12)
14:27:06.619 at Module.require (node:internal/modules/cjs/loader:1028:19)
14:27:06.638 at require (node:internal/modules/cjs/helpers:102:18)
14:27:06.639 at Object.<anonymous> (/Users/jycloud/Documents/项目/乐享大东/lxdd-member/node_modules/@dcloudio/uni-cli-shared/lib/index.js:67:5)
14:27:06.655 at Module._compile (node:internal/modules/cjs/loader:1126:14)

2023-09-20 14:28 负责人:无 分享
已邀请:
h***@outlook.com

h***@outlook.com

请问下是怎么解决的,是webpack版本冲突了吗?

1***@qq.com

1***@qq.com

如果是通过HBuilder创建的项目,添加vite.config.js后, 就不需要安装 @dcloudio/vite-plugin-uni,不然运行会报错

该问题目前已经被锁定, 无法添加新回复