#Vite parse error because of uncompatible file formats

11 messages · Page 1 of 1 (latest)

dusk echo
#

I am using vite's import.meta.glob() to generate a list of download links out of the directory applications which is located inside public and looks like this:

public/applications/
├── Citrix_Workspace
│   ├── Mac
│   │   └── citrix_workspace.dmg
│   ├── Windows
│   │   └── citrix_workspace.exe
│   └── img
│       └── citrix_workspace.jpg
└── Visual_Studio_Code
    ├── Mac
    │   └── visual_studio_code.dmg
    ├── Windows
    │   └── visual_studio_code.exe
    └── img
        └── visual_studio_code.png

It works fine, but the error comes when I want to build the project by executing npm run build.

It looks like this:

[vite:build-import-analysis] Parse error @:2:1031

I am using a windows subsystem for linux with Ubuntu installed. The parse error comes because of the incompatible file formats like .exe and .dmg.

Can I do anything to properly build all of it with my current setup without getting an error?

heavy yarrow
#

Hello! Vite's import.meta.glob is intended to be used to eventually import those files, in your case it'll generate code like:

const modules = {
  'visual_studio_code.exe': () => import('visual_studio_code.exe'),
  'visual_studio_code.dmg': () => import('visual_studio_code.dmg'),
}

Which, as you can probably expect, doesn't really work since you can't import those files in Node

#

If you're just looking for the file paths, a tool like fast-glob or globby is more appropriate

dusk echo
#

And that they work essentially the same except some extra functionalities with fast-glob

heavy yarrow
#

Ah no, they're completely separate tools!

#

I can understand the confusion though, since they're similarly named

dusk echo
#

Well, then someone told me wrong.

#

So I would not be able to achieve what I want with import.meta.glob()?

heavy yarrow
#

Nope, neither with Astro.glob (since they do the same thing)

dusk echo
#

I spent hours on this problem because multiple people recommended me to use import.meta.glob() 😩