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

new URL(url, import.meta.url) pattern broken for javascript modules in production #9309

Closed
7 tasks done
shamrin opened this issue Jul 23, 2022 · 0 comments · Fixed by #9399
Closed
7 tasks done

new URL(url, import.meta.url) pattern broken for javascript modules in production #9309

shamrin opened this issue Jul 23, 2022 · 0 comments · Fixed by #9399
Labels
p4-important Violate documented behavior or significantly improves performance (priority)

Comments

@shamrin
Copy link
Contributor

shamrin commented Jul 23, 2022

new URL(url, import.meta.url) pattern broken for .js assets in production

// main.js
function getJsUrl(name) {
  return new URL(`./sub/${name}.js`, import.meta.url).href
}
console.log(getJsUrl('a'))
// sub/a.js
export default class a {
  name = 'a'
}

The above works fine in npm run dev:

https://vitejs-vite-ohe6tf--5173.local.webcontainer.io/sub/a.js

However, it's broken in npm run build && npm run preview, showing class .toString():

https://vitejs-vite-ohe6tf--4173.local.webcontainer.io/class%20a%7Bconstructor()%7Bl(this,%22name%22,%22a%22)%7D%7D

https://vitejs.dev/guide/assets.html#new-url-url-import-meta-url

Reproduction

https://stackblitz.com/edit/vitejs-vite-ohe6tf?file=main.js

System Info

System:
    OS: Linux 5.0 undefined
    CPU: (4) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 0 Bytes / 0 Bytes
    Shell: 1.0 - /bin/jsh
  Binaries:
    Node: 16.14.2 - /usr/local/bin/node
    Yarn: 1.22.10 - /bin/yarn
    npm: 7.17.0 - /bin/npm
  npmPackages:
    vite: ^3.0.1 => 3.0.2 

Used Package Manager

npm

Logs

No response

Validations

@sapphi-red sapphi-red added the p4-important Violate documented behavior or significantly improves performance (priority) label Jul 24, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Aug 12, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
p4-important Violate documented behavior or significantly improves performance (priority)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants