Property 'glob' does not exist on type 'ImportMeta'.ts
Asked Answered
A

2

6

Context

I am new to Vite and with very little experience in Laravel, I am trying to use Vite with Laravel for asset bundling.

I'm following instructions from Laravel official documentation : https://laravel.com/docs/9.x/vite#blade-processing-static-assets

Since I'm using TypeScript, So my entry point file name is : resources/ts/app.ts

When I try to write

import.meta.glob([ 
  '../resources/img/..',
]);

I am able to get Property 'glob' does not exist on type 'ImportMeta'.ts(2339). I understand once files are build, I have to use <img src="{{ Vite::asset('resources/images/logo.png') }}"> to be able to see file, But since I'm skipping to update the app.ts file.

I am able to see logo.png as <imgsrc="https://sensitiveUrl.com/logo.a766f7e6.js"

I am trying to bundle static assets ( images ), just like how I did with css/js.

Africah answered 9/3, 2023 at 13:59 Comment(0)
C
10

Add "types": ["vite/client"] to compilerOptions in tsconfig.json in the project root directory.

tsconfig.json

Also your vite.config.js file should configured correctly.

Capel answered 22/3, 2023 at 20:6 Comment(3)
I also needed to add "./node_modules" to the typeRoots configuration for this to workMillham
@ChristianC so am ISabu
so how do you configure vite.config.js correctly?Rogerrogerio
L
0

I'm using Vitepress with TypeScript and just fixed this issue by adding "vite": "*" to my devDependencies

Edit: I also added "vue": "*" in the end (other similar issues)

Lavone answered 15/4, 2023 at 19:57 Comment(1)
You are not supposed to use "*" for any dependency, ever. This means you will install the latest version, no matter what, even it's a major, breaking change. And if you go long enough, hunting down what version you do want will be tricky because you don't know what version worked.Laurice

© 2022 - 2024 — McMap. All rights reserved.