TypeError:react__WEBPACK_IMPORTED_MODULE_0___default.a.createContext 不是一个函数(react 前端,node 后端)
2021-01-02
1206
因此,我尝试在本地托管一个项目,但在打开 localhost 时出现错误。我提供了控制台显示的内容、在 localhost:3000 上看到的内容以及来自前端和后端的 packageJson。我认为这可能与错误的版本有关,导致它崩溃,因为我看过类似的帖子,但我不确定。如有必要,我很乐意提供更多信息。
这是控制台显示的内容:
[0] Find the server at: http://localhost:3001/
[0] Connected to Redis
[0] Connected to MongoDB
[1] [1] ℹ 「wds」: Project is running at http://192.168.2.103/
[1] [1] ℹ 「wds」: webpack output is served from
[1] [1] ℹ 「wds」: Content not from webpack is served from /Users/taroholtappels/Desktop/rustwebsite-master/client/public
[1] [1] ℹ 「wds」: 404s will fallback to /
[1] [1] Starting the development server...
[1] [1]
[0] Updated prices!
[1] [1] Compiled with warnings.
这是我在打开 localhost 3000 时看到的内容
TypeError: react__WEBPACK_IMPORTED_MODULE_0___default.a.createContext is not a function
Module../node_modules/react-notifications/node_modules/react-transition-group/esm/TransitionGroupContext.js
node_modules/react-notifications/node_modules/react-transition-group/esm/TransitionGroupContext.js:2
1 | import React from 'react';
> 2 | export default React.createContext(null);
这是来自前端的 PackageJson:
"private": true,
"proxy": "http://localhost:3001",
"dependencies": {
"body-parser": "^1.17.1",
"bootstrap": "^3.3.7",
"express-jwt": "^5.3.0",
"express-session": "^1.15.2",
"font-awesome": "^4.7.0",
"gsap": "^1.20.6",
"history": "^4.6.1",
"immutability-helper": "^2.2.0",
"jsonwebtoken": "^7.4.0",
"jwt-decode": "^2.2.0",
"moment": "^2.18.1",
"passport": "^0.3.2",
"passport-steam": "^1.0.8",
"react": "^15.6.2",
"react-addons-css-transition-group": "^15.5.2",
"react-bootstrap": "^0.31.0",
"react-circular-progressbar": "^0.1.4",
"react-countup": "^2.1.1",
"react-dom": "^15.6.2",
"react-fontawesome": "^1.6.1",
"react-lightweight-tooltip": "0.0.4",
"react-modal": "^1.7.7",
"react-notifications": "^1.3.0",
"react-progressbar.js": "^0.2.0",
"react-redux": "^5.0.4",
"react-router": "^4.1.1",
"react-router-bootstrap": "^0.24.2",
"react-router-dom": "^4.1.1",
"react-router-redux": "^5.0.0-alpha.6",
"redux": "^3.6.0",
"redux-logger": "^3.0.6",
"redux-persist": "^4.8.0",
"redux-thunk": "^2.2.0",
"semantic-ui-css": "^2.2.10",
"semantic-ui-react": "^0.70.0",
"socket.io": "^1.7.3",
"socket.io-client": "^2.0.1",
"socketio-jwt": "^4.5.0"
},
"devDependencies": {
"babel-plugin-add-module-exports": "^1.0.2",
"babel-plugin-react-transform": "^3.0.0",
"babel-plugin-transform-decorators-legacy": "^1.3.4",
"babel-plugin-transform-react-display-name": "^6.23.0",
"babel-plugin-transform-runtime": "^6.23.0",
"babel-plugin-typecheck": "^3.9.0",
"babel-preset-es2015": "^6.24.1",
"babel-preset-react": "^6.24.1",
"babel-preset-stage-0": "^6.24.1",
"babel-register": "^6.24.1",
"concurrently": "^3.4.0",
"node-sass": "^4.5.2",
"react-scripts": "^3.4.1"
以及来自后端的 Packagejson
"private": true,
"dependencies": {
"babel-cli": "^6.26.0",
"babel-core": "^6.26.3",
"babel-plugin-add-module-exports": "^1.0.2",
"babel-plugin-transform-runtime": "^6.23.0",
"babel-plugin-typecheck": "^3.9.0",
"babel-preset-es2015": "^6.24.1",
"babel-preset-stage-0": "^6.24.1",
"babel-register": "^6.24.1",
"bluebird": "^3.5.0",
"body-parser": "^1.17.1",
"connect-mongo": "^3.2.0",
"express": "^4.17.1",
"express-session": "^1.15.2",
"jsonwebtoken": "^8.5.1",
"jwt-decode": "^2.2.0",
"moment": "^2.18.1",
"mongoose": "^5.9.10",
"mongoose-auto-increment": "^5.0.1",
"node-fetch": "^2.6.0",
"passport": "^0.4.1",
"passport-steam": "^1.0.8",
"path": "^0.12.7",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"react-redux": "^5.1.2",
"react-transition-group": "^1.2.1",
"redis": "^3.0.2",
"redis-server": "^1.2.2",
"request": "^2.81.0",
"socket.io": "^2.0.1",
"socketio-jwt": "^4.5.0",
"steam-totp": "^2.1.1",
"steam-tradeoffer-manager": "^2.10.1",
"steam-user": "^4.12.4",
"steamcommunity": "^3.40.1"
1个回答
如果您使用的是版本 15(在前端),则 React contexts 的最新版本直到版本 16.3 才可用。您应该更新到版本 16.3/更高版本,如果无法更新,请使用旧版本文档。 https://reactjs.org/docs/legacy-context.html
Jon Baltz
2021-01-02