[vite] Pre-transform error: Cannot find package pnpm路径过长导致运行报错

下了套vue3的代码,执行pnpm install初始化,使用vite启动,启动后访问就会报错

报错信息

e 复制代码
 ERROR  16:40:53 [vite] Pre-transform error: Cannot find package 'E:\work\VSCodeProjectWork\jeecg\xxxxxxxxx-next\xxxxxxxxx-next-jeecgBoot-vue3\node_modules\.pnpm\@vitejs+plugin-vue-jsx@https+++registry.npmmirror.com+@vitejs+plugin-vue-jsx+-+plugin-vue-jsx_wpfjsfrcyfhppiaqhs2qki2ffu\node_modules\@babel\plugin-transform-typescript\package.json' imported from E:\work\VSCodeProjectWork\jeecg\xxxxxxxxx-next\xxxxxxxxx-next-jeecgBoot-vue3\node_modules\.pnpm\@vitejs+plugin-vue-jsx@https+++registry.npmmirror.com+@vitejs+plugin-vue-jsx+-+plugin-vue-jsx_wpfjsfrcyfhppiaqhs2qki2ffu\node_modules\@vitejs\plugin-vue-jsx\dist\index.cjs
Did you mean to import @babel+plugin-transform-typescript@https+++registry.npmmirror.com+@babel+plugin-transform-typ_t6dvr774uyzoiatluosu5niumu/node_modules/@babel/plugin-transform-typescript/lib/index.js?

 ERROR  16:41:02 [vite] Internal server error: Cannot find package 'E:\work\VSCodeProjectWork\jeecg\xxxxxxxxx-next\xxxxxxxxx-next-jeecgBoot-vue3\node_modules\.pnpm\@vitejs+plugin-vue-jsx@https+++registry.npmmirror.com+@vitejs+plugin-vue-jsx+-+plugin-vue-jsx_wpfjsfrcyfhppiaqhs2qki2ffu\node_modules\@babel\plugin-transform-typescript\package.json' imported from E:\work\VSCodeProjectWork\jeecg\xxxxxxxxx-next\xxxxxxxxx-next-jeecgBoot-vue3\node_modules\.pnpm\@vitejs+plugin-vue-jsx@https+++registry.npmmirror.com+@vitejs+plugin-vue-jsx+-+plugin-vue-jsx_wpfjsfrcyfhppiaqhs2qki2ffu\node_modules\@vitejs\plugin-vue-jsx\dist\index.cjs
Did you mean to import @babel+plugin-transform-typescript@https+++registry.npmmirror.com+@babel+plugin-transform-typ_t6dvr774uyzoiatluosu5niumu/node_modules/@babel/plugin-transform-typescript/lib/index.js?
  Plugin: vite:vue-jsx
  File: E:/work/VSCodeProjectWork/jeecg/xxxxxxxxx-next/xxxxxxxxx-next-jeecgBoot-vue3/src/utils/factory/createAsyncComponent.tsx
      at legacyMainResolve (node:internal/modules/esm/resolve:214:26)
      at packageResolve (node:internal/modules/esm/resolve:840:14)
      at moduleResolve (node:internal/modules/esm/resolve:910:20)
      at defaultResolve (node:internal/modules/esm/resolve:1130:11)
      at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:396:12)
      at ModuleLoader.resolve (node:internal/modules/esm/loader:365:25)
      at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:240:38)
      at ModuleLoader.import (node:internal/modules/esm/loader:328:34)
      at importModuleDynamically (node:internal/modules/cjs/loader:1261:33)
      at importModuleDynamicallyWrapper (node:internal/vm/module:430:21)
      at importModuleDynamicallyCallback (node:internal/modules/esm/utils:186:14)
      at TransformContext.transform (E:\work\VSCodeProjectWork\jeecg\xxxxxxxxx-next\xxxxxxxxx-next-jeecgBoot-vue3\node_modules\.pnpm\@vitejs+plugin-vue-jsx@https+++registry.npmmirror.com+@vitejs+plugin-vue-jsx+-+plugin-vue-jsx_wpfjsfrcyfhppiaqhs2qki2ffu\node_modules\@vitejs\plugin-vue-jsx\dist\index.cjs:84:13)
      at Object.transform (file:///E:/work/VSCodeProjectWork/jeecg/xxxxxxxxx-next/xxxxxxxxx-next-jeecgBoot-vue3/node_modules/.pnpm/vite@5.2.13_@types+node@20.14.2_less@4.2.0/node_modules/vite/dist/node/chunks/dep-DEPSZ3SS.js:52318:62)
      at async loadAndTransform (file:///E:/work/VSCodeProjectWork/jeecg/xxxxxxxxx-next/xxxxxxxxx-next-jeecgBoot-vue3/node_modules/.pnpm/vite@5.2.13_@types+node@20.14.2_less@4.2.0/node_modules/vite/dist/node/chunks/dep-DEPSZ3SS.js:55073:29)
      at async viteTransformMiddleware (file:///E:/work/VSCodeProjectWork/jeecg/xxxxxxxxx-next/xxxxxxxxx-next-jeecgBoot-vue3/node_modules/.pnpm/vite@5.2.13_@types+node@20.14.2_less@4.2.0/node_modules/vite/dist/node/chunks/dep-DEPSZ3SS.js:64920:32)

同样的代码再同事电脑里就可以正常运行,

找到了个文章,解决方案是换个文件夹,原因的特殊字符,
jenkins目录下的vue3项目------pnpm install后运行报错------奇葩问题解决

我尝试了一下,将_改为了-,不好使,
E:\work\VSCodeProjectWork\jeecg\xxxxxxxxx-next\xxxxxxxxx-next-jeecgBoot-vue3

同级换个文件夹,不好使
E:\work\VSCodeProjectWork\jeecg\xxxxxxxxx_next\xxxxxxxxx-next-vue3

放在根目录下的A文件夹里,,好使,,
E:\A

按照原文件夹的名字拼接在一起变成了个巨长的文件夹名,不好使
E:\workVSCodeProjectWorkjeecgxxxxxxxxx_nextxxxxxxxxx-next-jeecgBoot-vue3

更改稍短点的路径,好使
E:\work\VSCodeProjectWork\jeecg\xxxxxxxxx_next\vue3

由此得出的pnpm不能在特别长的文件夹下使用

它的机制产生巨长的路径E:\work\VSCodeProjectWork\jeecg\xxxxxxxxx-next\xxxxxxxxx-next-jeecgBoot-vue3\node_modules\.pnpm\@vitejs+plugin-vue-jsx@https+++registry.npmmirror.com+@vitejs+plugin-vue-jsx+-+plugin-vue-jsx_wpfjsfrcyfhppiaqhs2qki2ffu\node_modules\@babel\plugin-transform-typescript\package.json' imported from E:\work\VSCodeProjectWork\jeecg\xxxxxxxxx-next\xxxxxxxxx-next-jeecgBoot-vue3\node_modules\.pnpm\@vitejs+plugin-vue-jsx@https+++registry.npmmirror.com+@vitejs+plugin-vue-jsx+-+plugin-vue-jsx_wpfjsfrcyfhppiaqhs2qki2ffu\node_modules\@vitejs\plugin-vue-jsx\dist\index.cjs实测已经561个字符了,与好使的路径只差26个字符,猜测是要控制在512以内,去除\ 536,536-26=510,也许就是答案吧,,

相关推荐
秦jh_18 分钟前
【Linux】多线程(概念,控制)
linux·运维·前端
蜗牛快跑21331 分钟前
面向对象编程 vs 函数式编程
前端·函数式编程·面向对象编程
Dread_lxy32 分钟前
vue 依赖注入(Provide、Inject )和混入(mixins)
前端·javascript·vue.js
涔溪1 小时前
Ecmascript(ES)标准
前端·elasticsearch·ecmascript
榴莲千丞1 小时前
第8章利用CSS制作导航菜单
前端·css
奔跑草-2 小时前
【前端】深入浅出 - TypeScript 的详细讲解
前端·javascript·react.js·typescript
羡与2 小时前
echarts-gl 3D柱状图配置
前端·javascript·echarts
guokanglun2 小时前
CSS样式实现3D效果
前端·css·3d
咔咔库奇2 小时前
ES6进阶知识一
前端·ecmascript·es6
前端郭德纲2 小时前
浏览器是加载ES6模块的?
javascript·算法