lisonge / vite-plugin-monkey

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

打包后monkeyWindow上的key构造异常 #163

Closed rachpt closed 4 months ago

rachpt commented 4 months ago

提示:

userscript.html?name=mt-work-enhancement.user.js&id=20b35579-0c2f-4001-ae64-150e7bb31f60:741  Uncaught (in promise) TypeError: Failed to construct 'URL': Invalid URL
    at Object.execute (userscript.html?name=mt-work-enhancement.user.js&id=20b35579-0c2f-4001-ae64-150e7bb31f60:741:35)
    at r (userscript.html?name=mt-work-enhancement.user.js&id=20b35579-0c2f-4001-ae64-150e7bb31f60:44:3638)
    at v (userscript.html?name=mt-work-enhancement.user.js&id=20b35579-0c2f-4001-ae64-150e7bb31f60:44:4074)
    at userscript.html?name=mt-work-enhancement.user.js&id=20b35579-0c2f-4001-ae64-150e7bb31f60:44:3551

module.meta::: 值为 {url: './__entry.js', resolve: ƒ}

打包后异常位置:

image

对应plugin代码位置:

image

dev模式正常,build后异常,手动将打包后的 module.meta.url 位置改成 module.meta.url?.startsWith('http') ? module.meta.url : location.href 后正常。 咨询一下优雅一点的解决办法。

lisonge commented 4 months ago

https://github.com/lisonge/vite-plugin-monkey?tab=readme-ov-file#how-to-properly-build-a-library-using-gm_api

    esbuildOptions: (options) => {
      options.alias = {
        'vite-plugin-monkey/dist/client': 'vite-plugin-monkey/dist/native',
      };
    },
lisonge commented 4 months ago

https://github.com/lisonge/vite-plugin-monkey/releases/tag/v4.0.1

rachpt commented 4 months ago

感谢回复&修复,刚刚本地改 vite-plugin-monkey 的代码一直没有修复。 排查了一圈是 @sec-ant/gm-fetch 这个包引入的 vite-plugin-monkey 旧版本的代码,还的他那边更新才能彻底解决。

image