-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
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
with vue cannot use import.meta.url object directly - new URL(url, import.meta.url) - #10863
Closed
7 tasks done
Labels
p3-minor-bug
An edge case that only affects very specific usage (priority)
Comments
In fact this bug occurred on each new URL(x, import.meta.url) may be due to regex /\bnew\s+URL\s*\(\s*('[^']+'|"[^"]+"|`[^`]+`)\s*,\s*import\.meta\.url\s*,?\s*\)/g in vite/packages/vite/src/node/plugins/assetImportMetaUrl.ts Lines 40 to 41 in 9c808cd
|
eltorio
changed the title
with vite cannot use import.meta object directly
with vite cannot use import.meta.url object directly
Nov 10, 2022
eltorio
changed the title
with vite cannot use import.meta.url object directly
with vue cannot use import.meta.url object directly
Nov 10, 2022
eltorio
changed the title
with vue cannot use import.meta.url object directly
with vue cannot use import.meta.url object directly - new URL(url, import.meta.url) -
Nov 10, 2022
my actual ugly workaround is to create a @/plugins/viteHelper.ts ( I defined @ as src path alias for vue-cli compatibility) /**
*
* @param url absolute path of asset (must begin with @/assets/)
* @returns a vite transformed url string
*/
export function $require(url:string):string{
return new URL(`../assets/${url.replace('@/assets/','')}`,import.meta.url).href
} and in my .vue files <template>
<span v-for="locale in $i18n.availableLocales" :key="`locale-${locale}`" :id="`sp-${locale}`">
<img @click="changeLang(locale)" class="cursor-pointerw-6 h-6" :alt="locale"
:src="$require(`@/assets/lang/${locale.substring(3).toLowerCase()}.svg`)" />
</span>
</template>
<script setup lang="ts">
import { $require } from '@/plugins/viteHelper.js'
// … rest of code
</script> |
sapphi-red
added
plugin: vue
p3-minor-bug
An edge case that only affects very specific usage (priority)
labels
Nov 11, 2022
sapphi-red
added a commit
to sapphi-red/vite
that referenced
this issue
Nov 14, 2022
9 tasks
patak-dev
pushed a commit
that referenced
this issue
Nov 14, 2022
patak-dev
pushed a commit
to vitejs/vite-plugin-vue
that referenced
this issue
Dec 2, 2022
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Describe the bug
With vue 3.2.44
in main.ts this code fail to run
this code compiles but does not have the correct behavior (see https://vitejs.dev/guide/assets.html#new-url-url-import-meta-url )
I opened an issue on vue/core but it is related to vite
see original post vuejs/core#7093
Reproduction
https://github.com/eltorio/vue-sfc-bug
Steps to reproduce
git clone https://github.com/eltorio/vue-sfc-bug.git cd vue-sfc-bug npm i npm run dev
repository was created with
edit main.ts
edit tsconfig.json
run npm run dev and see error:
I created a second branch with this small diff for reproduction
non working: https://github.com/eltorio/vue-sfc-bug
compiling but bad behavior: https://github.com/eltorio/vue-sfc-bug/tree/workaround
#on branch workaround git diff main
System Info
System: OS: macOS 13.1 CPU: (16) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz Memory: 101.22 MB / 16.00 GB Shell: 5.8.1 - /bin/zsh Binaries: Node: 16.18.0 - /usr/local/bin/node Yarn: 1.22.18 - /usr/local/bin/yarn npm: 8.19.2 - /usr/local/bin/npm Browsers: Brave Browser: 107.1.45.118 Chrome: 107.0.5304.110 Firefox: 106.0.5 Safari: 16.1 npmPackages: vue: ^3.2.44 => 3.2.44
Used Package Manager
npm
Logs
Validations
The text was updated successfully, but these errors were encountered: