lisonge / vite-plugin-monkey

A vite plugin server and build your.user.js for userscript engine like Tampermonkey, Violentmonkey, Greasemonkey, ScriptCat
MIT License
1.41k stars 73 forks source link

编译报错:RollupError: Could not resolve "./main-0f36d1c7.js" from "./index-c6f221e0.js" #86

Closed zuley closed 1 year ago

zuley commented 1 year ago
zhuleyi@zhuleyideMacBook-Pro segi-browser-ext % pnpm run build

> segi-browser-ext@0.0.0 build /Users/zhuleyi/SEGI/SEGI-CODE/WEB Public/segi-browser-ext
> vue-tsc --noEmit && vite build

vite v4.3.9 building for production...
✓ 2453 modules transformed.
rendering chunks (9)...Could not resolve "./main-0f36d1c7.js" from "./index-c6f221e0.js"
file: ./index-c6f221e0.js
[monkey:finalBundle] Could not resolve "./main-0f36d1c7.js" from "./index-c6f221e0.js"
file: ./index-c6f221e0.js
✓ built in 2.64s
error during build:
RollupError: Could not resolve "./main-0f36d1c7.js" from "./index-c6f221e0.js"
    at error (file:///Users/zhuleyi/SEGI/SEGI-CODE/WEB%20Public/segi-browser-ext/node_modules/.pnpm/rollup@3.23.0/node_modules/rollup/dist/es/shared/node-entry.js:2124:30)
    at ModuleLoader.handleInvalidResolvedId (file:///Users/zhuleyi/SEGI/SEGI-CODE/WEB%20Public/segi-browser-ext/node_modules/.pnpm/rollup@3.23.0/node_modules/rollup/dist/es/shared/node-entry.js:23990:24)
    at file:///Users/zhuleyi/SEGI/SEGI-CODE/WEB%20Public/segi-browser-ext/node_modules/.pnpm/rollup@3.23.0/node_modules/rollup/dist/es/shared/node-entry.js:23952:26
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
 ELIFECYCLE  Command failed with exit code 1.

执行打包报这个错,不知道哪里有问题。node 19.2

lisonge commented 1 year ago

看起来是 dynamic import 的问题,可否把复现代码压缩为 zip 上传到 issues 评论区

zuley commented 1 year ago

segi-browser-ext的副本.zip 这个是整个代码的压缩包

看起来是 dynamic import 的问题,可否把复现代码压缩为 zip 上传到 issues 评论区

lisonge commented 1 year ago

https://github.com/lisonge/vite-plugin-monkey/blob/060b33eaf68850d7b8f111d25a76b50aad49d9cb/packages/vite-plugin-monkey/src/node/plugins/finalBundle.ts#L79

dynamic import 下存在某个模块被两个模块分别导入,之前的逻辑是用到一次就删除了,导致第二次解析导入的时候找不到模块

lisonge commented 1 year ago

fied in v3.2.2

可以更新依赖试试,我这边是构建成功的

image

lisonge commented 1 year ago

@zuley 这个问题解决了没