React App错误:找不到模块“ react-error-overlay / middleware”

时间:2019-02-18 16:25:33

标签: reactjs

这非常令人沮丧。自昨天早上以来,我一直在处理这个问题。我有一个超过一年没有启动过的React应用程序。上一次启动该应用程序时,它运行完美。但是我想在本地进行处理,并且在一年前运行良好时使用完全相同的package.json在浏览器中失败,并显示以下错误消息:

TypeError: Cannot read property 'ReactCurrentOwner' of undefined

由于package.json已有一岁了,所以今天我运行了npm update,并且当我尝试运行该程序时收到以下错误:

Error: Cannot find module 'react-error-overlay/middleware'

旧package.json

{
  "name": "mazzo-react-test",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "auth0-lock": "^10.24.3",
    "autoprefixer": "7.1.2",
    "babel-core": "6.25.0",
    "babel-eslint": "7.2.3",
    "babel-jest": "20.0.3",
    "babel-loader": "7.1.1",
    "babel-preset-react-app": "^3.1.2",
    "babel-runtime": "6.23.0",
    "case-sensitive-paths-webpack-plugin": "2.1.1",
    "chalk": "^1.1.3",
    "css-loader": "0.28.4",
    "dotenv": "4.0.0",
    "eslint": "4.4.1",
    "eslint-config-react-app": "^2.1.0",
    "eslint-loader": "1.9.0",
    "eslint-plugin-flowtype": "2.35.0",
    "eslint-plugin-import": "2.7.0",
    "eslint-plugin-jsx-a11y": "5.1.1",
    "eslint-plugin-react": "7.1.0",
    "extract-text-webpack-plugin": "3.0.0",
    "file-loader": "0.11.2",
    "fs-extra": "3.0.1",
    "html-webpack-plugin": "2.29.0",
    "jest": "20.0.4",
    "konva": "^1.7.6",
    "material-ui": "^0.18.7",
    "object-assign": "4.1.1",
    "postcss-flexbugs-fixes": "3.2.0",
    "postcss-loader": "2.0.6",
    "promise": "8.0.1",
    "react": "^15.6.2",
    "react-dev-utils": "^3.1.3",
    "react-dom": "^15.6.2",
    "react-error-overlay": "^1.0.10",
    "react-konva": "^1.7.16",
    "react-relay": "0.10.0",
    "react-relay-network-layer": "1.3.9",
    "react-router": "3.0.2",
    "react-router-relay": "0.13.5",
    "react-tap-event-plugin": "^2.0.1",
    "relay-commit-mutation-promise": "^1.0.1",
    "style-loader": "0.18.2",
    "styled-components": "^2.4.1",
    "sw-precache-webpack-plugin": "0.11.4",
    "url-loader": "0.5.9",
    "webpack": "3.5.1",
    "webpack-dev-server": "2.7.1",
    "webpack-manifest-plugin": "1.2.1",
    "whatwg-fetch": "2.0.3"
  },
  "scripts": {
    "start": "node scripts/start.js",
    "build": "GRAPHQL_ENDPOINT=https://api.graph.cool/relay/v1/cj63i9kajpzhw0153segab1wa node scripts/build.js",
    "test": "node scripts/test.js --env=jsdom"
  },
  "jest": {
    "collectCoverageFrom": [
      "src/**/*.{js,jsx}"
    ],
    "setupFiles": [
      "<rootDir>/config/polyfills.js"
    ],
    "testMatch": [
      "<rootDir>/src/**/__tests__/**/*.js?(x)",
      "<rootDir>/src/**/?(*.)(spec|test).js?(x)"
    ],
    "testEnvironment": "node",
    "testURL": "http://localhost",
    "transform": {
      "^.+\\.(js|jsx)$": "<rootDir>/node_modules/babel-jest",
      "^.+\\.css$": "<rootDir>/config/jest/cssTransform.js",
      "^(?!.*\\.(js|jsx|css|json)$)": "<rootDir>/config/jest/fileTransform.js"
    },
    "transformIgnorePatterns": [
      "[/\\\\]node_modules[/\\\\].+\\.(js|jsx)$"
    ],
    "moduleNameMapper": {
      "^react-native$": "react-native-web"
    },
    "moduleFileExtensions": [
      "web.js",
      "js",
      "json",
      "web.jsx",
      "jsx",
      "node"
    ]
  },
  "babel": {
    "plugins": [
      "react-relay"
    ],
    "presets": [
      "react-app"
    ]
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "devDependencies": {
    "babel-plugin-react-relay": "^0.10.0"
  }
}

新的或更新的package.json

    {
  "name": "mazzo-react-test",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "auth0-lock": "^11.14.0",
    "autoprefixer": "9.4.7",
    "babel-core": "6.26.3",
    "babel-eslint": "10.0.1",
    "babel-jest": "24.1.0",
    "babel-loader": "8.0.5",
    "babel-preset-react-app": "^7.0.1",
    "babel-runtime": "6.26.0",
    "case-sensitive-paths-webpack-plugin": "2.2.0",
    "chalk": "^2.4.2",
    "css-loader": "2.1.0",
    "dotenv": "6.2.0",
    "eslint": "5.14.0",
    "eslint-config-react-app": "^3.0.7",
    "eslint-loader": "2.1.2",
    "eslint-plugin-flowtype": "3.4.2",
    "eslint-plugin-import": "2.16.0",
    "eslint-plugin-jsx-a11y": "6.2.1",
    "eslint-plugin-react": "7.12.4",
    "extract-text-webpack-plugin": "3.0.2",
    "file-loader": "3.0.1",
    "fs-extra": "7.0.1",
    "html-webpack-plugin": "3.2.0",
    "jest": "24.1.0",
    "konva": "^2.6.0",
    "material-ui": "^0.20.2",
    "object-assign": "4.1.1",
    "postcss-flexbugs-fixes": "4.1.0",
    "postcss-loader": "3.0.0",
    "promise": "8.0.2",
    "react": "^16.8.2",
    "react-dev-utils": "^7.0.3",
    "react-dom": "^16.8.2",
    "react-error-overlay": "^5.1.3",
    "react-konva": "^16.8.2-0",
    "react-relay": "2.0.0",
    "react-relay-network-layer": "2.2.1",
    "react-router": "4.3.1",
    "react-router-relay": "0.14.0",
    "react-tap-event-plugin": "^3.0.3",
    "relay-commit-mutation-promise": "^1.0.0",
    "style-loader": "0.23.1",
    "styled-components": "^4.1.3",
    "sw-precache-webpack-plugin": "0.11.5",
    "url-loader": "1.1.2",
    "webpack": "4.29.5",
    "webpack-dev-server": "3.1.14",
    "webpack-manifest-plugin": "2.0.4",
    "whatwg-fetch": "3.0.0"
  },
  "scripts": {
    "start": "node scripts/start.js",
    "build": "GRAPHQL_ENDPOINT=https://api.graph.cool/relay/v1/cj63i9kajpzhw0153segab1wa node scripts/build.js",
    "test": "node scripts/test.js --env=jsdom"
  },
  "jest": {
    "collectCoverageFrom": [
      "src/**/*.{js,jsx}"
    ],
    "setupFiles": [
      "<rootDir>/config/polyfills.js"
    ],
    "testMatch": [
      "<rootDir>/src/**/__tests__/**/*.js?(x)",
      "<rootDir>/src/**/?(*.)(spec|test).js?(x)"
    ],
    "testEnvironment": "node",
    "testURL": "http://localhost",
    "transform": {
      "^.+\\.(js|jsx)$": "<rootDir>/node_modules/babel-jest",
      "^.+\\.css$": "<rootDir>/config/jest/cssTransform.js",
      "^(?!.*\\.(js|jsx|css|json)$)": "<rootDir>/config/jest/fileTransform.js"
    },
    "transformIgnorePatterns": [
      "[/\\\\]node_modules[/\\\\].+\\.(js|jsx)$"
    ],
    "moduleNameMapper": {
      "^react-native$": "react-native-web"
    },
    "moduleFileExtensions": [
      "web.js",
      "js",
      "json",
      "web.jsx",
      "jsx",
      "node"
    ]
  },
  "babel": {
    "plugins": [
      "react-relay"
    ],
    "presets": [
      "react-app"
    ]
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "devDependencies": {
    "babel-plugin-react-relay": "^0.10.0"
  }
}

为什么?

1 个答案:

答案 0 :(得分:0)

因此,您遇到的是npm模块的工作方式-您遇到的这个问题并非react所独有。我们不能期望为您解决这个问题-但我可以尝试为您指明正确的方向。

我将以您的package.json中的依赖项为例,该行:
"react-error-overlay": "^1.0.10"在版本号旁边有一个尖号(^)。

这意味着在大多数情况下,当您运行npm installnpm update时,npm将抢占该软件包的最新版本,数字。

如果您比较帖子中的两个不同的package.json文件,您会注意到,由于相当多的依赖项,跳过了多个主要软件包版本。如果您查找语义版本,则会发现主要版本冲突通常是由于模块中的重大更改所致。

例如:
旧版:"react-error-overlay": "^1.0.10"
新增:"react-error-overlay": "^5.1.3"

在这里,您从主要版本1.x.x跳至5.x.x。仅此模块就超过4个重大更改。

基本上,这意味着该模块无法以以前的方式工作。如果您的项目工作了一年左右-并且运行了npm update-那么当您使用新的主要软件包版本时,它很可能现在会失败。

如果您只是希望您的项目像以前一样工作,那么我建议您这样做:
取得package.json的原始版本,然后删除版本号中的^插入符号。
然后清除项目中的node_modules文件夹。
然后运行npm install

这应该引入与您以前使用的模块非常相似的模块版本。尝试看看它是否随后运行。如果是这样,请从那里分别更新您的依赖项-并找出导致您的项目中断的主要版本变更。

也:
至于您遇到的typeError,它来自react-konva,如本期主题中所述:
https://github.com/konvajs/react-konva/issues/147#issuecomment-346217504

react-konva版本1.1.6适用于react v16及更高版本

使用以下版本定位目标react v15
"react-konva": "1.1.6"