【问题标题】:With next.js, why did I suddenly start seeing Module not found: Error: Can't resolve 'fs'?使用 next.js,为什么我突然开始看到 Module not found: Error: Can't resolve 'fs'?
【发布时间】:2020-12-03 10:09:03
【问题描述】:

我什么也没做,但我使用的是"next": "9.4.4",我明白了:

Module not found: Can't resolve 'fs' in 'web/node_modules/graceful-fs'
Could not find files for /app/d/[id] in .next/build-manifest.json
ModuleNotFoundError: Module not found: Error: Can't resolve 'fs' in 'web/node_modules/graceful-fs'

我做错了什么?

【问题讨论】:

    标签: node.js webpack next.js


    【解决方案1】:

    您似乎不在/api 目录中。客户端代码将无法导入fs,只有 API 文件会

    【讨论】:

    • 但我没有在任何地方使用fs
    • 嗯,这很奇怪。当发生这样的事情时,我通常会删除node_modules 和package-lock.json 并再次运行npm install。有一次,我不得不重新安装解决问题的 node.js
    • 做到了。也许我会尝试不同版本的节点?
    【解决方案2】:
    npm WARN deprecated urix@0.1.0: Please see https://github.com/lydell/urix#deprecated
    npm WARN deprecated chokidar@2.1.8: Chokidar 2 will break on node v14+. Upgrade to chokidar 3 with 15x less dependencies.
    npm WARN deprecated resolve-url@0.2.1: https://github.com/lydell/resolve-url#deprecated
    npm WARN deprecated fsevents@1.2.13: fsevents 1 will break on node v14+ and could be using insecure binaries. Upgrade to fsevents 2.
    

    对我来说,问题似乎是我正在运行 Node 14.7.0。我在构建以下 NextJS 客户端时收到的警告表明这是问题所在。

    {
          "name": "client",
          "version": "1.0.0",
          "description": "Serverside rendered React client with NestJS",
          "main": "index.js",
          "scripts": {
            "dev": "next"
          },
          "keywords": [],
          "author": "Will Nielsen",
          "license": "ISC",
          "dependencies": {
            "@nielsendigital/ms-common": "^1.1.17",
            "axios": "^0.20.0",
            "bootstrap": "^4.5.2",
            "next": "^10.0.2",
            "react": "^17.0.1",
            "react-dom": "^17.0.1",
            "react-stripe-checkout": "^2.6.3"
          }
        }
    

    我不清楚如何在 NextJS 中将 fsevents 升级到 v2。

    【讨论】:

      猜你喜欢
      • 2019-05-28
      • 2020-04-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-19
      • 1970-01-01
      • 2019-03-11
      • 2019-01-14
      相关资源
      最近更新 更多