Nuxt 3 + Vite由于fsevents.node而无法构建

bvjveswy  于 2023-05-22  发布在  Node.js
关注(0)|答案(1)|浏览(163)

在将Nuxt更新到3.4.2并将types/node更新到18.15.13之后,我在尝试构建时得到以下错误:
npm run dev:

✘ [ERROR] No loader is configured for ".node" files: node_modules/fsevents/fsevents.node

    node_modules/fsevents/fsevents.js:13:23:
      13 │ const Native = require("./fsevents.node");
         ╵                        ~~~~~~~~~~~~~~~~~

 ERROR  [unhandledRejection] Build failed with 1 error:                                                                                                     9:03:37 AM
node_modules/fsevents/fsevents.js:13:23: ERROR: No loader is configured for ".node" files: node_modules/fsevents/fsevents.node

  node_modules/fsevents/fsevents.js:13:23: ERROR: No loader is configured for ".node" files: node_modules/fsevents/fsevents.node
  at failureErrorWithLog (node_modules/esbuild/lib/main.js:1636:15)
  at node_modules/esbuild/lib/main.js:1048:25
  at node_modules/esbuild/lib/main.js:1512:9
  at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

这就是包。json:

"private": true,
  "scripts": {
    "build": "nuxt build",
    "dev2": "nuxt dev",
    "dev": "NODE_TLS_REJECT_UNAUTHORIZED=0 nuxt dev --https --ssl-cert localhost.pem --ssl-key localhost-key.pem",
    "generate": "nuxt generate",
    "preview": "nuxt preview",
    "postinstall": "nuxt prepare"
  },
  "devDependencies": {
    "@fortawesome/fontawesome-free": "^6.2.1",
    "@types/node": "^18.15.11",
    "nuxt": "^3.4.0",
    "sass": "^1.57.1",
    "vue-gtag-next": "^1.14.0",
    "vue-sound": "^0.1.10"
  },
  "dependencies": {
    "@mdi/font": "^7.1.96",
    "@storyblok/nuxt": "^5.3.4",
    "@vueuse/core": "^9.11.1",
    "gsap": "^3.11.5",
    "vuetify": "^3.1.14"
  }
}

我试过清理缓存和删除node_modules,但新安装并没有解决这个问题。

vxqlmq5t

vxqlmq5t1#

在nuxt配置中从vite中排除fsevents。

//nuxt.config.ts

export default defineNuxtConfig({
  //...
  
  vite: {
    //...
    optimizeDeps: { exclude: ["fsevents"] },
  }
})

我可以确认@Jonathan的评论有效。把它作为一个答案张贴出来,让未来的读者看清楚。谢谢Jonathan!

相关问题