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

@rollup/plugin-data-uri fails #1428

Closed
3 tasks done
patak-dev opened this issue Jan 8, 2021 · 2 comments
Closed
3 tasks done

@rollup/plugin-data-uri fails #1428

patak-dev opened this issue Jan 8, 2021 · 2 comments
Labels
enhancement New feature or request

Comments

@patak-dev
Copy link
Member

patak-dev commented Jan 8, 2021

  • Read the docs.
  • Use Vite >=2.0. (1.x is no longer supported)
  • If the issue is related to 1.x -> 2.0 upgrade, read the Migration Guide first.

I am testing the official rollup plugins to check compatibility issues

Describe the bug

From the implementation of @rollup/plugin-data-uri, it looks that this plugin should work in Vite.

It fails in dev with an error in the browser:

Failed to load module script: The server responded with a non-JavaScript MIME type of "application/json". Strict MIME type checking is enforced for module scripts per HTML spec.

And during build with error:

TypeError: Cannot read property 'imports' of undefined
at getPreloadLinksForChunk ({path}\node_modules\vite\dist\node\chunks\dep-85227760.js:36877:36)
at {path}\node_modules\vite\dist\node\chunks\dep-85227760.js:36885:34
at Array.forEach ()
at getPreloadLinksForChunk ({path}\node_modules\vite\dist\node\chunks\dep-85227760.js:36884:31)
at Object.generateBundle ({path}i\node_modules\vite\dist\node\chunks\dep-85227760.js:36928:28)
at {path}\node_modules\rollup\dist\shared\rollup.js:18781:25

Reproduction

I created a repro using the vanilla template here https://github.com/matias-capeletto/vite-rollup-plugin-data-uri

System Info

  • vite version: 2.0.0-beta.12
  • Operating System: Windows 10 Home, 10.0.18363 N/A Build 18363
  • Node version: v15.5.0
  • Package manager and version: yarn v1.22.10
@antfu antfu added enhancement New feature or request and removed pending triage labels Jan 8, 2021
@yyx990803
Copy link
Member

yyx990803 commented Jan 8, 2021

This is kinda expected, because importing from data URI is actually a native esm feature. In this case

import batman from "data:text/javascript;, export default 'hi'"

Vite won't rewrite the URL and the import doesn't even hit the dev server during dev. This probably currently fails during build, which we should provide built-in support for.

And for the JSON case - since you actually can't natively import json from data URIs, it fails. Although I'm not quite sure in what case would this actually be useful when you can simply import from an actual JSON file...

If we were to make json data-uri imports work, we'd have to rewrite all data URIs to a special, valid path that would hit the dev server (e.g. /@data-uri/xxxx), and then decode, transform, and send it back.

@yyx990803
Copy link
Member

Ok, so js data-uri imports were previously excluded from build which works natively, but is sub-optimal and would break in the legacy build, so I added build handling in 4fd0b86

I don't think we will actually need @rollup/plugin-data-uri in this case.

@github-actions github-actions bot locked and limited conversation to collaborators Jul 16, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants