dcloudio / uni-app

A cross-platform framework using Vue.js
https://uniapp.dcloud.io
Apache License 2.0
40.15k stars 3.64k forks source link

`3.0.0-4010520240507001` 版本使用 `vitest` 出现异常:`Error: Cannot find module 'vuex/package.json'` #4939

Open sunpm opened 5 months ago

sunpm commented 5 months ago

报错信息:

Error: Cannot find module 'vuex/package.json'
Require stack:
- 当前项目路径/node_modules/.pnpm/@dcloudio+uni-cli-shared@3.0.0-4010520240507001_@vueuse+core@9.13.0_vue@3.4.27_typescript@4.9_rzxhs7gpnzk4ytytzonhc33jty/node_modules/@dcloudio/uni-cli-shared/dist/resolve.js
- 当前项目路径/node_modules/.pnpm/@dcloudio+uni-cli-shared@3.0.0-4010520240507001_@vueuse+core@9.13.0_vue@3.4.27_typescript@4.9_rzxhs7gpnzk4ytytzonhc33jty/node_modules/@dcloudio/uni-cli-shared/dist/hbx/env.js
- 当前项目路径/node_modules/.pnpm/@dcloudio+uni-cli-shared@3.0.0-4010520240507001_@vueuse+core@9.13.0_vue@3.4.27_typescript@4.9_rzxhs7gpnzk4ytytzonhc33jty/node_modules/@dcloudio/uni-cli-shared/dist/hbx/index.js
- 当前项目路径/node_modules/.pnpm/@dcloudio+uni-cli-shared@3.0.0-4010520240507001_@vueuse+core@9.13.0_vue@3.4.27_typescript@4.9_rzxhs7gpnzk4ytytzonhc33jty/node_modules/@dcloudio/uni-cli-shared/dist/utils.js
- 当前项目路径/node_modules/.pnpm/@dcloudio+uni-cli-shared@3.0.0-4010520240507001_@vueuse+core@9.13.0_vue@3.4.27_typescript@4.9_rzxhs7gpnzk4ytytzonhc33jty/node_modules/@dcloudio/uni-cli-shared/dist/mp/ast.js
- 当前项目路径/node_modules/.pnpm/@dcloudio+uni-cli-shared@3.0.0-4010520240507001_@vueuse+core@9.13.0_vue@3.4.27_typescript@4.9_rzxhs7gpnzk4ytytzonhc33jty/node_modules/@dcloudio/uni-cli-shared/dist/mp/index.js
- 当前项目路径/node_modules/.pnpm/@dcloudio+uni-cli-shared@3.0.0-4010520240507001_@vueuse+core@9.13.0_vue@3.4.27_typescript@4.9_rzxhs7gpnzk4ytytzonhc33jty/node_modules/@dcloudio/uni-cli-shared/dist/index.js
- 当前项目路径/node_modules/.pnpm/@dcloudio+vite-plugin-uni@3.0.0-4010520240507001_@vueuse+core@9.13.0_vue@3.4.27_typescript@4._crphgclmu3iqau2a7xw2aejlaa/node_modules/@dcloudio/vite-plugin-uni/dist/index.js
- 当前项目路径/vite.config.ts
- 当前项目路径/node_modules/.pnpm/vite@5.2.8_@types+node@20.12.11_sass@1.77.1_terser@5.31.0/node_modules/vite/dist/node/chunks/dep-whKeNLxG.js
    at Module._resolveFilename (node:internal/modules/cjs/loader:1077:15)
    at Module._resolveFilename (当前项目路径/node_modules/.pnpm/module-alias@2.2.3/node_modules/module-alias/index.js:49:29)
    at Function.resolve (node:internal/modules/cjs/helpers:127:19)
    at resolveBuiltIn (当前项目路径/node_modules/.pnpm/@dcloudio+uni-cli-shared@3.0.0-4010520240507001_@vueuse+core@9.13.0_vue@3.4.27_typescript@4.9_rzxhs7gpnzk4ytytzonhc33jty/node_modules/@dcloudio/uni-cli-shared/dist/resolve.js:95:20)
    at config (当前项目路径/node_modules/.pnpm/@dcloudio+uni-h5-vite@3.0.0-4010520240507001_@vueuse+core@9.13.0_vue@3.4.27_typescript@4.9.5__7niez6hclpkbmvwu64khh7gxga/node_modules/@dcloudio/uni-h5-vite/dist/plugins/ssr.js:32:105)
    at runConfigHook (file://当前项目路径/node_modules/.pnpm/vite@5.2.8_@types+node@20.12.11_sass@1.77.1_terser@5.31.0/node_modules/vite/dist/node/chunks/dep-whKeNLxG.js:68712:31)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async resolveConfig (file://当前项目路径/node_modules/.pnpm/vite@5.2.8_@types+node@20.12.11_sass@1.77.1_terser@5.31.0/node_modules/vite/dist/node/chunks/dep-whKeNLxG.js:68167:14)
    at async _createServer (file://当前项目路径/node_modules/.pnpm/vite@5.2.8_@types+node@20.12.11_sass@1.77.1_terser@5.31.0/node_modules/vite/dist/node/chunks/dep-whKeNLxG.js:64655:20)
    at async createViteServer (file://当前项目路径/node_modules/.pnpm/vitest@1.6.0_@types+node@20.12.11_jsdom@16.7.0_sass@1.77.1_terser@5.31.0/node_modules/vitest/dist/vendor/cli-api.E07AF1Yq.js:10388:18) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '当前项目路径/node_modules/.pnpm/@dcloudio+uni-cli-shared@3.0.0-4010520240507001_@vueuse+core@9.13.0_vue@3.4.27_typescript@4.9_rzxhs7gpnzk4ytytzonhc33jty/node_modules/@dcloudio/uni-cli-shared/dist/resolve.js',
    '当前项目路径/node_modules/.pnpm/@dcloudio+uni-cli-shared@3.0.0-4010520240507001_@vueuse+core@9.13.0_vue@3.4.27_typescript@4.9_rzxhs7gpnzk4ytytzonhc33jty/node_modules/@dcloudio/uni-cli-shared/dist/hbx/env.js',
    '当前项目路径/node_modules/.pnpm/@dcloudio+uni-cli-shared@3.0.0-4010520240507001_@vueuse+core@9.13.0_vue@3.4.27_typescript@4.9_rzxhs7gpnzk4ytytzonhc33jty/node_modules/@dcloudio/uni-cli-shared/dist/hbx/index.js',
    '当前项目路径/node_modules/.pnpm/@dcloudio+uni-cli-shared@3.0.0-4010520240507001_@vueuse+core@9.13.0_vue@3.4.27_typescript@4.9_rzxhs7gpnzk4ytytzonhc33jty/node_modules/@dcloudio/uni-cli-shared/dist/utils.js',
    '当前项目路径/node_modules/.pnpm/@dcloudio+uni-cli-shared@3.0.0-4010520240507001_@vueuse+core@9.13.0_vue@3.4.27_typescript@4.9_rzxhs7gpnzk4ytytzonhc33jty/node_modules/@dcloudio/uni-cli-shared/dist/mp/ast.js',
    '当前项目路径/node_modules/.pnpm/@dcloudio+uni-cli-shared@3.0.0-4010520240507001_@vueuse+core@9.13.0_vue@3.4.27_typescript@4.9_rzxhs7gpnzk4ytytzonhc33jty/node_modules/@dcloudio/uni-cli-shared/dist/mp/index.js',
    '当前项目路径/node_modules/.pnpm/@dcloudio+uni-cli-shared@3.0.0-4010520240507001_@vueuse+core@9.13.0_vue@3.4.27_typescript@4.9_rzxhs7gpnzk4ytytzonhc33jty/node_modules/@dcloudio/uni-cli-shared/dist/index.js',
    '当前项目路径/node_modules/.pnpm/@dcloudio+vite-plugin-uni@3.0.0-4010520240507001_@vueuse+core@9.13.0_vue@3.4.27_typescript@4._crphgclmu3iqau2a7xw2aejlaa/node_modules/@dcloudio/vite-plugin-uni/dist/index.js',
    '当前项目路径/vite.config.ts',
    '当前项目路径/node_modules/.pnpm/vite@5.2.8_@types+node@20.12.11_sass@1.77.1_terser@5.31.0/node_modules/vite/dist/node/chunks/dep-whKeNLxG.js'
  ]
}

将版本回退至3.0.0-4010420240430002则没有该错误

复现

https://github.com/sunpm/vitesse-uniapp-vue3/tree/test-issue

系统信息

System: OS: macOS 12.6.5 CPU: (4) x64 Intel(R) Core(TM) i5-6500 CPU @ 3.20GHz Memory: 387.30 MB / 32.00 GB Shell: 5.8.1 - /bin/zsh Binaries: Node: 18.17.1 - ~/.nvm/versions/node/v18.17.1/bin/node Yarn: 1.22.17 - /usr/local/bin/yarn npm: 9.6.7 - ~/.nvm/versions/node/v18.17.1/bin/npm pnpm: 9.1.1 - ~/.nvm/versions/node/v18.17.1/bin/pnpm

Xiphin commented 5 months ago

@Otto-J 复现工程: https://github.com/sunpm/vitesse-uniapp-vue3

sunpm commented 5 months ago

复现:https://github.com/sunpm/vitesse-uniapp-vue3/tree/test-issue

sunpm commented 5 months ago

@Otto-J 复现工程: sunpm/vitesse-uniapp-vue3

有一个报错不是 uniapp 的问题,去掉重开一个分支了

Ares-Chang commented 3 months ago

@Otto-J 您好,这个问题已经好长时间没有进展了,Ares-Chang/uni-vitest-bug-repo 这是一个 bug 最小复现的 demo ,拉下来直接可以运行。

直接使用的官方 ts 模板并添加了 vitest ,但是它运行时会加载 vuex 依赖,这是项目所不需要的,如果安装了 vuex 没有问题。

这应该是哪个地方依赖加载有问题,但是我们能力比较浅薄,找不到问题,麻烦官方跟进一下,感谢!

非常感谢 DCloud 及成员的维护及付出。

依赖版本

{
  "dependencies": {
    "@dcloudio/uni-app": "3.0.0-4020420240722002",
    "vue": "^3.4.21"
  },
  "devDependencies": {
    "@dcloudio/uni-automator": "3.0.0-4020420240722002",
    "@dcloudio/uni-cli-shared": "3.0.0-4020420240722002",
    "@dcloudio/uni-stacktracey": "3.0.0-4020420240722002",
    "@dcloudio/vite-plugin-uni": "3.0.0-4020420240722002",
    "@vue/runtime-core": "^3.4.21",
    "@vue/tsconfig": "^0.1.3",
    "typescript": "^4.9.4",
    "vite": "5.2.8",
    "vitest": "^2.0.5",
    "vue-tsc": "^1.0.24"
  }
}
luofengwz commented 2 months ago

@Otto-J 您好,这个问题已经好长时间没有进展了,Ares-Chang/uni-vitest-bug-repo 这是一个 bug 最小复现的 demo ,拉下来直接可以运行。

直接使用的官方 ts 模板并添加了 vitest ,但是它运行时会加载 vuex 依赖,这是项目所不需要的,如果安装了 vuex 没有问题。

这应该是哪个地方依赖加载有问题,但是我们能力比较浅薄,找不到问题,麻烦官方跟进一下,感谢!

非常感谢 DCloud 及成员的维护及付出。

依赖版本

{
  "dependencies": {
    "@dcloudio/uni-app": "3.0.0-4020420240722002",
    "vue": "^3.4.21"
  },
  "devDependencies": {
    "@dcloudio/uni-automator": "3.0.0-4020420240722002",
    "@dcloudio/uni-cli-shared": "3.0.0-4020420240722002",
    "@dcloudio/uni-stacktracey": "3.0.0-4020420240722002",
    "@dcloudio/vite-plugin-uni": "3.0.0-4020420240722002",
    "@vue/runtime-core": "^3.4.21",
    "@vue/tsconfig": "^0.1.3",
    "typescript": "^4.9.4",
    "vite": "5.2.8",
    "vitest": "^2.0.5",
    "vue-tsc": "^1.0.24"
  }
}

我把这个路径中的vuex/package.json注释就可以运行了: /nodemodules/.pnpm/@dcloudio+uni-h5-vite@3.0.0-4010520240507001@vueuse+core@9.13.0_vue@3.4.27_typescript@4.9.5__7niez6hclpkbmvwu64khh7gxga/node_modules/@dcloudio/uni-h5-vite/dist/plugins/ssr.js:32:105

lihe6666 commented 2 months ago

这破玩意还没解决,还要手动改!!!