You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Vite项目启动与构建报错:未配置.node文件加载器

解决Vite项目中fsevents相关加载错误

方法1:非macOS环境排除fsevents依赖

fsevents是仅macOS系统需要的文件监听依赖,Windows/Linux用户可直接在package.json里配置忽略安装:

  • 打开package.json,添加如下配置:
"optionalDependencies": {
  "fsevents": "*"
}

删除node_modules和对应锁文件后重装依赖:

# npm
rm -rf node_modules package-lock.json && npm install

# yarn
rm -rf node_modules yarn.lock && yarn install

# pnpm
rm -rf node_modules pnpm-lock.yaml && pnpm install

方法2:配置Vite跳过fsevents处理

macOS用户或不想修改依赖配置的话,在vite.config.ts中添加规则让Rollup忽略.node文件:

import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';

export default defineConfig({
  plugins: [react()],
  build: {
    rollupOptions: {
      external: ['fsevents'],
    },
  },
  optimizeDeps: {
    exclude: ['fsevents'],
  },
});

方法3:降级Vite版本

部分新版本Vite和fsevents存在兼容性问题,可尝试降级到稳定的4.x版本:

# npm
npm install vite@4.5.2 --save-dev

# yarn
yarn add vite@4.5.2 --dev

# pnpm
pnpm add vite@4.5.2 -D

方法4:修正tsconfig.node.json配置

确保tsconfig.node.json适配Vite打包逻辑,配置如下:

{
  "compilerOptions": {
    "composite": true,
    "skipLibCheck": true,
    "module": "ESNext",
    "moduleResolution": "bundler",
    "allowSyntheticDefaultImports": true
  },
  "include": ["vite.config.ts"]
}

内容的提问来源于stack exchange,提问作者jose corredor

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.01 19:06:17