lisonge / vite-plugin-monkey

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

使用vue的js模板构建的项目,无法使用pnpm run dev 预览脚本。I can't preview the script. #26

Closed Discut closed 1 year ago

Discut commented 1 year ago

我的环境 My context

发生的问题 Problems that occur

使用命令「pnpm run dev」预览脚本,添加脚本后打开匹配网站,在控制台出现如下错误 Use the command "pnpm run dev" to preview the project, an error occurred at the console, the project preview failed. image client.ts:470:16 in image style.css:1:96 in image

如何复现 Reproduction of the problem

修改vite.config.js 中的 Modify the file "vite.config.js " image

更多 More

当我直接构建项目然后导入至油猴插件时,脚本就能正常运行了。 我尝试过直接使用模板在该网站预览,还是会发生同样的错误。 使用该项目在其他网站预览(例如哔哩哔哩),就不会发生这种问题。

When I build the project directly and import it into the Monkey, the script works fine. I preview the template project on the website and the same error still occurs. If i preview the project on other websites ( For example, bilibili ), the error does not occur.

以上就是我的问题了,感谢大佬抽空查看我的问题,如果有解决方案就更好了。(一个前端小白)也许我可能遗留了某些配置文件吧,求大佬轻喷。

lisonge commented 1 year ago

请问你创建的项目的仓库地址是什么,可否发出来看看

Discut commented 1 year ago

请问你创建的项目的仓库地址是什么,可否发出来看看

这是项目地址 https://github.com/Discut/ID_School 我并没有修改太多,使用pnpm create monkey 创建的模板项目在那个网站下预览也会爆同样的错误。

lisonge commented 1 year ago

找到原因了,是 https://mooc.yibinu.edu.cn/js/core.min.js 这个太旧了,覆盖了你的浏览器的 api,导致 Map 这个对象缺失属性

解决方法之一是 在 devtools 阻止这个 url image image

Discut commented 1 year ago

找到原因了,是 https://mooc.yibinu.edu.cn/js/core.min.js 这个太旧了,覆盖了你的浏览器的 api,导致 Map 这个对象缺失属性

解决方法之一是 在 devtools 阻止这个 url image image

感谢大佬解决我的问题。

lisonge commented 1 year ago

另一种解决方法是 直接覆盖它的 polyfill image