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

Dynamic (@vite-ignore'd) import with // breaks JS transform #5051

Closed
7 tasks done
gluck opened this issue Sep 23, 2021 · 3 comments · Fixed by #14910
Closed
7 tasks done

Dynamic (@vite-ignore'd) import with // breaks JS transform #5051

gluck opened this issue Sep 23, 2021 · 3 comments · Fixed by #14910
Labels
p3-minor-bug An edge case that only affects very specific usage (priority)

Comments

@gluck
Copy link
Contributor

gluck commented Sep 23, 2021

Describe the bug

Importing a dynamic URL with '//' in it will break the output JS:

// works
import(/*@vite-ignore*/ `https://unpkg.com/lodash`);

// works
import(/*@vite-ignore*/ `https://unpkg.com/${'lodash'}`);

// doesn't work (unexpected end of input)
import(/*@vite-ignore*/ `https://unpkg.com//${'lodash'}`);

This is cause by regex replacement here:

.replace(/\/\*[\s\S]*?\*\/|([^\\:]|^)\/\/.*$/gm, '')

// raw === "/*@vite-ignore*/ `https://unpkg.com//${'lodash'}`"
          const url = rawUrl
            .replace(/\/\*[\s\S]*?\*\/|([^\\:]|^)\/\/.*$/gm, '')
            .trim()
// url === "`https://unpkg.co"

Reproduction

Minimal reproduction is here:
https://stackblitz.com/edit/vite-pgxelk?file=main.js

System Info

No plugin, both local & stackblitz webcontainer.
[email protected]

Used Package Manager

npm

Logs

No response

Validations

@Ontopic
Copy link

Ontopic commented Sep 23, 2021

Ah, thanks, thought I was going mad.

@haoqunjiang haoqunjiang added p3-minor-bug An edge case that only affects very specific usage (priority) and removed pending triage labels Oct 10, 2021
@bluwy
Copy link
Member

bluwy commented Mar 20, 2022

Still reproducible with Vite 2.9.0-beta.4, but it's not crashing the server now. Instead it gives a false warning that the vite-ignore comment is needed, even though already specified:

00:43:27 [vite] warning: 
/home/projects/vite-bbsbsc/main.js
2  |  
3  |  // works
4  |  import(/*@vite-ignore*/ `https://unpkg.com/${'lodash'}`);
   |                          ^
5  |  
6  |  // works
The above dynamic import cannot be analyzed by vite.
See https://github.com/rollup/plugins/tree/master/packages/dynamic-import-vars#limitations for supported dynamic import formats. If this is intended to be left as-is, you can use the /* @vite-ignore */ comment inside the import() call to suppress this warning.

  Plugin: vite:import-analysis
  File: /home/projects/vite-bbsbsc/main.js

Copy link

stackblitz bot commented Nov 7, 2023

Fix this issue in StackBlitz Codeflow Start a new pull request in StackBlitz Codeflow.

@github-actions github-actions bot locked and limited conversation to collaborators Nov 24, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
p3-minor-bug An edge case that only affects very specific usage (priority)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants