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

Invalid glob import syntax: pattern must start with "." or "/" #6883

Closed
7 tasks done
Rolanddoda opened this issue Feb 12, 2022 · 1 comment · Fixed by #6526
Closed
7 tasks done

Invalid glob import syntax: pattern must start with "." or "/" #6883

Rolanddoda opened this issue Feb 12, 2022 · 1 comment · Fixed by #6526

Comments

@Rolanddoda
Copy link

Describe the bug

My vite.config.js has an alias:

import { fileURLToPath, URL } from 'url';
import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [vue()],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url)),
    },
  },
});

So I can import components like import MyCmp from '@/components/MyCmp.vue'.

But when I use import.meta.glob('@/components/global/*.vue') Vite doesn't recognize the alias and error out with the message:

Invalid glob import syntax: pattern must start with "." or "/" (relative to project root)

It seems that Vite already knows that aliases do not work with import.meta.glob and says that pattern must start with "." or "/".

So if this is not a bug then this issue is a feature request to support aliases on import.meta.glob.

Reproduction

https://stackblitz.com/edit/vitejs-vite-ojnnbh?devtoolsheight=33&file=src/main.js

System Info

System:
    OS: Windows 10 10.0.22000
    CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
    Memory: 2.56 GB / 15.81 GB
  Binaries:
    Node: 14.15.1 - C:\Program Files\nodejs\node.EXE
    npm: 8.3.2 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Chrome: 98.0.4758.82
    Edge: Spartan (44.22000.120.0), Chromium (98.0.1108.50)
    Internet Explorer: 11.0.22000.120
  npmPackages:
    @vitejs/plugin-vue: ^2.1.0 => 2.1.0
    vite: ^2.8.1 => 2.8.1

Used Package Manager

npm

Logs

![image](https://user-images.githubusercontent.com/18482346/153714718-effc9a5c-19e7-4441-8777-5c80501b3b1a.png)

Validations

@bluwy
Copy link
Member

bluwy commented Feb 13, 2022

Duplicate of #5717

@bluwy bluwy marked this as a duplicate of #5717 Feb 13, 2022
@bluwy bluwy closed this as completed Feb 13, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Feb 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants