在Windows上使用Vite时,如何解决“错误:找不到模块‘fsevents’”?

Lus*_*bwe 7 javascript windows fsevents vite

我正在尝试在我的 Windows 机器上使用 Vite 进行 Web 开发项目。但是,我不断收到错误消息: Error: Cannot find module 'fsevents' [plugin:vite:import-analysis] 无法解析从“node_modules.vite\deps\chunk-7EWWWNQA.js?v=554e11ec 导入“fsevents” ”。该文件存在吗?

 async function loadFsEvents() { 
     try {
       ({ default: fsEvents } = await import("fsevents"));
   } catch (error2) {
     fsEventsImportError = error2; 
   }
Run Code Online (Sandbox Code Playgroud)

我已多次尝试卸载 fsevents 包并删除节点模块,但错误仍然存​​在。我还尝试运行命令 npmauditfix --force,但它也没有帮助。

如何解决此错误并在我的 Windows 计算机上使用 Vite?

小智 22

检查您的任何组件中是否有任何奇怪的导入。有时自动完成会意外导入内容。我刚刚通过删除解决了同样的问题

import { SplitVendorChunkCahe } from 'vite'
Run Code Online (Sandbox Code Playgroud)

文件中的行。