Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vite 5 - 404 on scripts when using base #61

Closed
renataogarcia opened this issue Feb 11, 2024 · 8 comments
Closed

Vite 5 - 404 on scripts when using base #61

renataogarcia opened this issue Feb 11, 2024 · 8 comments

Comments

@renataogarcia
Copy link
Contributor

When I upgrade to Vite 5, I get a 404 on scripts if base option is in use.

I've done some investigation, and found that what is causing the issue is likely to be this change on vite vitejs/vite#5657.

After the plugin calls transformHtml it changes:

<script type="module">
      console.log("TESTING")
</script>

into:

<script type="module" src="/@id/__x00__/myBase/test.html?html-proxy&index=0.js" />

This used to work before 5657, but now is no longer supported. Vite expects it to have the base in the url as below, otherwise it fails with 404:

<script type="module" src="/myBase/@id/__x00__/myBase/test.html?html-proxy&index=0.js" />

I've tested without using the template and it works fine as it resolves to:

<script type="module" src="/myBase/test.html?html-proxy&index=0.js" />

I've done a workaround to replace all ".@id/x00/" and prepend the base and it seems to work fine.

However, I'm not sure if this is a Vite issue, or a issue with the plugin, whether it is calling transformHtml with some missing options or Vite expects it to adjust the module url.

Please let me know your thoughts.

@emosheeep
Copy link
Owner

This plugin only handles html files you've configured in pages option, unmatched paths will be next() directly and handled by vite. 🤔

@renataogarcia
Copy link
Contributor Author

Sorry, I wasn't very clear, but the <script> tag is inside the .html files defined in option.

@emosheeep
Copy link
Owner

Did you mean the transformHtml provided by the plugin not the transformIndexHtml ( vite's plugin api)?

@renataogarcia
Copy link
Contributor Author

The later, transformIndexHtml

@emosheeep
Copy link
Owner

This plugin only handles html files you've configured in pages option, unmatched paths will be next() directly and handled by vite. 🤔

Maybe it was relevant about the rewrite rules or proxy config, I guess 🤔

@renataogarcia
Copy link
Contributor Author

I have rewrite rules disabled. I also tried enabling it to see if it would make a difference but it didn't.

The build output works fine and preview too, which to me, suggests that the change introduced in 5657 would also have to cater for virtual modules. I'll try to experiment a bit and see if that could be the case.

@emosheeep
Copy link
Owner

Thanks a lot, I'm in Spring Festival and busy now, don't have much time on here.

@emosheeep
Copy link
Owner

It seems this problem has been fixed in vite@6, and the issue has closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants