Search code examples
typescriptlaravellaravel-bladevite

Property 'glob' does not exist on type 'ImportMeta'.ts


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.


Solution

  • 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.