Property ‘glob’ does not exist on type ‘ImportMeta’.

huangapple go评论196阅读模式
英文:

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

问题

上下文

我对Vite和Laravel的经验非常有限,尝试在Laravel中使用Vite进行资源捆绑。

我正在遵循Laravel官方文档的指示:https://laravel.com/docs/9.x/vite#blade-processing-static-assets

由于我使用TypeScript,所以我的入口文件名是:resources/ts/app.ts

当我尝试写入

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

我得到了Property 'glob' does not exist on type 'ImportMeta'.ts(2339)。我理解一旦文件构建完成,我必须使用
<img src="{{ Vite::asset('resources/images/logo.png') }}">
来查看文件,但由于我跳过了更新app.ts文件。

我能够看到logo.png
<img src="https://sensitiveUrl.com/logo.a766f7e6.js"

我正在尝试捆绑静态资源(图片),就像我用css/js做的那样。

英文:

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([ 
  &#39;../resources/img/..&#39;,
]);

I am able to get Property &#39;glob&#39; does not exist on type &#39;ImportMeta&#39;.ts(2339). I understand once files are build, I have to use
&lt;img src=&quot;{{ Vite::asset(&#39;resources/images/logo.png&#39;) }}&quot;&gt;
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
&lt;imgsrc=&quot;https://sensitiveUrl.com/logo.a766f7e6.js&quot;

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

答案1

得分: 4

在项目根目录的tsconfig.json文件中,添加**"types": ["vite/client"]**到_compilerOptions_。

tsconfig.json

另外,确保你的vite.config.js文件已正确配置。

英文:

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.

答案2

得分: 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)

英文:

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

Edit: I also added &quot;vue&quot;: &quot;*&quot; in the end (other similar issues)

huangapple
  • 本文由 发表于 2023年3月9日 21:59:36
  • 转载请务必保留本文链接:https://go.coder-hub.com/75685623.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定