Uncaught TypeError: Cannot read property 'Consumer' of undefined
See original GitHub issue尝试使用 ant-design-pro,按照教程clone下来后,安装后启动,页面loading闪现一下之后一直白屏。打开console,显示错误: Uncaught TypeError: Cannot read property ‘Consumer’ of undefined
本机环境: Mac pro:10.14.3 node:8.11.3 npm:5.6.0
运行结果与错误如下:
my-project git:(master) npm start
> ant-design-pro@2.2.1 start /Users/sunny/Documents/practice/my-project
> cross-env APP_TYPE=site umi dev
Warning: Please use `require("react-router").matchPath` instead of `require("react-router/matchPath")`. Support for the latter will be removed in the next major release.
Warning: Please use `require("react-router").Router` instead of `require("react-router/Router")`. Support for the latter will be removed in the next major release.
Warning: Please use `require("react-router").Switch` instead of `require("react-router/Switch")`. Support for the latter will be removed in the next major release.
Warning: Please use `require("react-router").Route` instead of `require("react-router/Route")`. Support for the latter will be removed in the next major release.
✔ Webpack
Compiled successfully in 8.86s
WARNING Compiled with 1 warnings 13:44:24
warning in ./node_modules/react-router-dom/esm/react-router-dom.js
"export '__RouterContext' was not found in 'react-router'
File sizes after gzip:
2.01 MB umi-dlls/umi.dll.js
The bundle size is significantly larger than recommended.
Consider reducing it with code splitting: https://goo.gl/9VhYWB
You can also analyze the project dependencies: https://goo.gl/LeUzfb
[umi-plugin-dll] Build dll done
? message Probably:
nginx: master process /usr/local/opt/nginx/bin/nginx -g daemon off; (pid 2171)
in /usr/local
Would you like to run the app on another port instead? Yes
(node:13369) DeprecationWarning: Tapable.plugin is deprecated. Use new API on `.hooks` instead
Starting the development server...
✔ Webpack
Compiled successfully in 25.66s
Theme generated successfully
DONE Compiled successfully in 26055ms 13:44:58
App running at:
- Local: http://localhost:8001/ (copied to clipboard)
- Network: http://192.168.31.71:8001/
Uncaught TypeError: Cannot read property 'Consumer' of undefined
at Link.render (react-router-dom.js:148)
at finishClassComponent (react-dom.development.js:14695)
at updateClassComponent (react-dom.development.js:14650)
at beginWork (react-dom.development.js:15598)
at performUnitOfWork (react-dom.development.js:19266)
at workLoop (react-dom.development.js:19306)
at HTMLUnknownElement.callCallback (react-dom.development.js:149)
at Object.invokeGuardedCallbackDev (react-dom.development.js:199)
at invokeGuardedCallback (react-dom.development.js:256)
at replayUnitOfWork (react-dom.development.js:18532)
at renderRoot (react-dom.development.js:19422)
at performWorkOnRoot (react-dom.development.js:20296)
at performWork (react-dom.development.js:20208)
at performSyncWork (react-dom.development.js:20182)
at requestWork (react-dom.development.js:20051)
at scheduleWork (react-dom.development.js:19865)
at Object.enqueueSetState (react-dom.development.js:11144)
at DynamicComponent.umi../node_modules/react/cjs/react.development.js.Component.setState (react.development.js:335)
at dynamic.js:91
Issue Analytics
- State:
- Created 5 years ago
- Comments:12 (1 by maintainers)
Top Results From Across the Web
Cannot read properties of undefined (reading 'Consumer')
Current behavior Test fails with following error: TypeError: Cannot read properties of undefined (reading 'Consumer') at StackView.render ...
Read more >React 16.3 Context API -- Provider/Consumer issues
Your are getting TypeError: Cannot read property 'state' of undefined. Beacuse every time you call const { Provider, Consumer } ...
Read more >cannot read properties of undefined (reading 'consumer')
Your issue is that your .find() method is returning undefined , so you can't access properties on product such as .name as it...
Read more >Use ES6 Arrow Functions to Resolve "TypeError - Pluralsight
1TypeError: Cannot read property '<your property name>' of undefined ... This error informs you that this is undefined.
Read more >How to Read React Errors (fix 'Cannot read property of ...
This error usually means you're trying to use .map on an array, but that array isn't defined yet. That's often because the array...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Same issue. Like the react-router-dom has published 4.4.0
First, delete the symbol ‘^’ of
"react-router-dom": "^4.3.1"
frompackage.json.
Then, remove thepackage-lock.json
andnode_modules/
directory. Runnpm install
again.参考 https://github.com/sorrycc/blog/issues/82 ,别写死版本。。