“ImportMeta”类型上不存在属性“glob”。ts

问题描述 投票:0回答:2

背景

我是 Vite 新手,对 Laravel 的经验很少,我正在尝试将 Vite 与 Laravel 一起使用来进行资产捆绑。

我遵循 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
<imgsrc="https://sensitiveUrl.com/logo.a766f7e6.js"

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

typescript laravel laravel-blade vite
2个回答
4
投票

在项目根目录tsconfig.json中的compilerOptions中添加

"types": ["vite/client"]

tsconfig.json

您的 vite.config.js 文件也应该正确配置。


0
投票

我将 Vitepress 与 TypeScript 结合使用,并通过将

"vite": "*"
添加到我的
devDependencies

来解决此问题

编辑:我还在最后添加了

"vue": "*"
(其他类似问题)

© www.soinside.com 2019 - 2024. All rights reserved.