【问题标题】:Unable to run my nuxt project - can't resolve 'fsevents' in无法运行我的 nuxt 项目 - 无法解析“fsevents”
【发布时间】:2021-06-09 15:44:06
【问题描述】:

当我使用 npm run dev 运行我的 nuxt.js 项目时,我看到编译错误:

× Client
  Compiled with some errors in 12.53s


 WARN  Compiled with 2 warnings                                                                                                                                                                  friendly-errors 16:32:21  


 WARN  in ./node_modules/nodemon/lib/version.js                                                                                                                                                  friendly-errors 16:32:21  

Critical dependency: the request of a dependency is an expression                                                                                                                                friendly-errors 16:32:21  
                                                                                                                                                                                                 friendly-errors 16:32:21  

 WARN  in ./node_modules/chokidar/lib/fsevents-handler.js                                                                                                                                        friendly-errors 16:32:21  

Module not found: Error: Can't resolve 'fsevents' in 'C:\JDeveloper\mywork\Vue\my-project-fronted-test\node_modules\chokidar\lib'                                                              friendly-errors 16:32:21  
                                                                                                                                                                                                 friendly-errors 16:32:21  

 ERROR  Failed to compile with 13 errors                                                                                                                                                         friendly-errors 16:32:21  

These dependencies were not found:                                                                                                                                                               friendly-errors 16:32:21  
                                                                                                                                                                                                 friendly-errors 16:32:21  
* child_process in ./node_modules/nodemon/lib/version.js, ./node_modules/nodemon/lib/monitor/run.js and 1 other                                                                                  friendly-errors 16:32:21  
* fs in ./node_modules/chokidar/index.js, ./node_modules/chokidar/lib/fsevents-handler.js and 8 others                                                                                           friendly-errors 16:32:21  
                                                                                                                                                                                                 friendly-errors 16:32:21  
To install them, you can run: npm install --save child_process fs                                                                                                                                friendly-errors 16:32:21  
i Waiting for file changes                                                                                                                                                                                       16:32:21
i Memory usage: 449 MB (RSS: 633 MB)                                                                                                                                                                             16:32:21
i Listening on: http://localhost:8081/                                                                                                                                                                           16:32:21  

 WARN  Error from chokidar (C:\): Error: EBUSY: resource busy or locked, lstat 'C:\hiberfil.sys'                                                                                                                 16:32:22  

在浏览器中打开它后,我看到了很多这样的错误:

ERROR in ./node_modules/nodemon/lib/version.js
Module not found: Error: Can't resolve 'child_process' in 'C:\JDeveloper\mywork\Vue\my-project-fronted-test\node_modules\nodemon\lib'
ERROR in ./node_modules/nodemon/lib/spawn.js
Module not found: Error: Can't resolve 'child_process' in 'C:\JDeveloper\mywork\Vue\my-project-fronted-test\node_modules\nodemon\lib'
ERROR in ./node_modules/nodemon/lib/monitor/run.js
Module not found: Error: Can't resolve 'child_process' in 'C:\JDeveloper\mywork\Vue\my-project-fronted-test\node_modules\nodemon\lib\monitor'
ERROR in ./node_modules/pstree.remy/lib/index.js
Module not found: Error: Can't resolve 'child_process' in 'C:\JDeveloper\mywork\Vue\my-project-fronted-test\node_modules\pstree.remy\lib'
ERROR in ./node_modules/pstree.remy/lib/tree.js
Module not found: Error: Can't resolve 'child_process' in 'C:\JDeveloper\mywork\Vue\my-project-fronted-test\node_modules\pstree.remy\lib'
ERROR in ./node_modules/pstree.remy/lib/utils.js
Module not found: Error: Can't resolve 'child_process' in 'C:\JDeveloper\mywork\Vue\my-project-fronted-test\node_modules\pstree.remy\lib'
ERROR in ./node_modules/chokidar/index.js
Module not found: Error: Can't resolve 'fs' in 'C:\JDeveloper\mywork\Vue\my-project-fronted-test\node_modules\chokidar'

删除node_modules 文件夹和package-lock.json 文件后,我尝试再次安装所有软件包,但没有任何改变。 这是我的package.json 文件。

...
"author": "kojot",
  "private": true,
  "scripts": {
    "dev": "nuxt --port 8081",
    "dev:host": "nuxt --hostname 192.168.5.123 --port 8081",
    "build": "nuxt build",
    "start": "nuxt start",
    "generate": "nuxt generate",
    "export": "nuxt export",
    "serve": "nuxt serve"
  },
  "dependencies": {
    "@nuxtjs/auth": "^4.9.1",
    "@nuxtjs/axios": "^5.13.1",
    "@nuxtjs/proxy": "^1.3.3",
    "babel-polyfill": "^6.26.0",
    "cross-env": "^5.2.0",
    "element-ui": "^2.15.1",
    "lodash": "^4.17.21",
    "nuxt": "^2.15.3",
    "nuxt-i18n": "^6.21.0",
    "polish-plurals": "^1.1.0",
    "rsocket-core": "0.0.25",
    "rsocket-flowable": "0.0.25",
    "rsocket-websocket-client": "0.0.25",
    "uniqid": "^5.3.0",
    "vee-validate": "^3.4.5",
    "vue-cal": "^3.10.0",
    "vue-recaptcha": "^1.3.0",
    "vuex-map-fields": "^1.4.1"
  },
  "devDependencies": {
    "@nuxtjs/google-analytics": "^2.4.0",
    "@nuxtjs/moment": "^1.6.1",
    "@nuxtjs/vuetify": "^1.11.3",
    "nodemon": "^1.11.0"
  }
}

我使用的是 Windows 10 Pro 和最新的 node/npm 版本:

OS Name:                   Microsoft Windows 10 Pro
OS Version:                10.0.18363 N/A Build 18363

PS C:\> node -v
v14.16.0
PS C:\> npm -version
7.6.2

我可以做些什么来运行这个项目?

【问题讨论】:

    标签: node.js npm webpack nuxt.js


    【解决方案1】:

    这么愚蠢的错误...我发现在我的一个 vuex 存储文件中我有这个:

    import {
      reset
    } from "nodemon";
    

    当然不是我写的,是我写mutation时我的一些VSC插件添加的,叫reset()...编译错误太无意义了,我花了2天时间才找到这个错误。

    【讨论】:

    • 什么意思?我对 nuxt 项目有同样的问题,但不明白它与这行代码有什么关系。
    • 删除这一行,你可能不需要它。
    猜你喜欢
    • 1970-01-01
    • 2021-08-30
    • 2017-02-01
    • 1970-01-01
    • 2020-09-08
    • 1970-01-01
    • 2021-11-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多