code: 'MODULE_NOT_FOUND', requireStack: [... 即使模块可见且文​​件路径正确

code: 'MODULE_NOT_FOUND', requireStack: [... even when module is visible and the file path is correct

所以我在创建应用程序时遇到问题,我无法 运行 npm build 没有这个便便,

PS C:\Users\finnm\OneDrive\Desktop\Finn 的 stuff\NFT\DenOfDragons\minting_staking_dapp> npm start

minting_staking_dapp@0.1.0 start react-app-rewired start

node:internal/modules/cjs/loader:936
  throw err;
  ^

Error: Cannot find module 'C:\Users\finnm\OneDrive\Desktop\Finn's stuff\NFT\DenOfDragons\minting_staking_dapp\node_modules\react-scripts/config/webpack.config.dev'
Require stack:
- C:\Users\finnm\OneDrive\Desktop\Finn's stuff\NFT\DenOfDragons\minting_staking_dapp\node_modules\react-app-rewired\scripts\start.js
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
    at Function.Module._load (node:internal/modules/cjs/loader:778:27)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (C:\Users\finnm\OneDrive\Desktop\Finn's stuff\NFT\DenOfDragons\minting_staking_dapp\node_modules\react-app-rewired\scripts\start.js:9:23)
    at Module._compile (node:internal/modules/cjs/loader:1103:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1155:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    "C:\Users\finnm\OneDrive\Desktop\Finn's stuff\NFT\DenOfDragons\minting_staking_dapp\node_modules\react-app-rewired\scripts\start.js"
  ]
}
PS C:\Users\finnm\OneDrive\Desktop\Finn's stuff\NFT\DenOfDragons\minting_staking_dapp> 

模块在那里,路径是正确的,所以我不明白为什么找不到它

节点版本:16.14.0 npm 版本:8.5.2

这是我的 package.json

{
  "name": "minting_staking_dapp",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@testing-library/jest-dom": "^5.16.2",
    "@testing-library/react": "^12.1.3",
    "@testing-library/user-event": "^13.5.0",
    "contracts": "file:./SmartContractMetaData",
    "react": "^17.0.2",
    "react-dom": "^17.0.2",
    "react-scripts": "5.0.0",
    "react-app-rewired": "^1.6.2",  
    "web-vitals": "^2.1.4",
    "web3": "^1.7.0"
  },
  "scripts": {
    "start": "react-app-rewired start",
    "build": "react-app-rewired build",
    "test": "react-app-rewired test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": [
      "react-app",
      "react-app/jest"
    ]
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  },
  "devDependencies": {
    "assert": "^2.0.0",
    "crypto-browserify": "^3.12.0",
    "https-browserify": "^1.0.0",
    "os-browserify": "^0.3.0",
    "stream-browserify": "^3.0.0",
    "stream-http": "^3.2.0"
  }
}

和我的配置-overrides.js

const webpack = require('webpack');

module.exports = function override(config) {
    config.ignoreWarnings = [/Failed to parse source map/];

    const fallback = config.resolve.fallback || {};
    Object.assign(fallback, {
        "crypto": require.resolve("crypto-browserify"),
        "stream": require.resolve("stream-browserify"),
        "assert": require.resolve("assert"),
        "http": require.resolve("stream-http"),
        "https": require.resolve("https-browserify"),
        "os": require.resolve("os-browserify"),
        "url": require.resolve("url")
    })
    config.resolve.fallback = fallback;
    config.plugins = (config.plugins || []).concat([
        new webpack.ProvidePlugin({
            process: 'process/browser',
            Buffer: ['buffer', 'Buffer']
        })
    ])
    return config;
}

感谢您提供的任何帮助

您的路径似乎指向 OneDrive 位置 - OneDrive 模拟文件“存在”但实际上只下载它们 on-demand。这 可能 在您的上下文中不起作用…
尝试 right-click 有问题的文件和 select “始终保持……”。

这是解决方法

它找不到该模块的原因是因为在 react-scripts 2+ 中,文件是 renamed/merged 和 create-react-app 的正常 webpack.config。

如果您使用的是 react-app-rewired 1.6.2。对于 react-scripts 版本 2+ 的版本,你需要使用 react-app-rewired 2+,部分是因为这个原因,部分是因为 Webpack 4 也有重大变化 - 版本 1.6.2 不是 Webpack 4+兼容。