TypeError:react__WEBPACK_IMPORTED_MODULE_5 ___ default.a.PropTypes未定义

时间:2018-10-08 01:18:23

标签: react-redux

我收到“ TypeError:react__WEBPACK_IMPORTED_MODULE_5 ___ default.a.PropTypes未定义”。我只是一个初学者。我无法想出什么问题了。

代码如下:

import React from 'react';

class App extends React.Component {
  render(){
    let txt = this.props.txt
    return (
      <div>
        <h1>{txt}</h1>
      </div>
      
    ) 
  }
}

App.propTypes = {
  txt: React.PropTypes.string,
  cat: React.PropTypes.number.isRequired
}

export default App

1 个答案:

答案 0 :(得分:1)

新手也在这里。我认为在您的特定情况下,您需要:

import ReactDOM from 'react-dom';

我一直在努力解决类似的问题,但是使用react-bootstrap,尽管我的具体错误是:

TypeError: react_bootstrap_lib__WEBPACK_IMPORTED_MODULE_7___default.a is undefined 

我在想我的问题可能与缺少依赖项有关,但不能完全确定我缺少还是没有导入。

这是完整的控制台输出,希望有人能看到并知道 react-bootstrap 1.0 beta和我需要导入的内容:

The development server has disconnected.
Refresh the page if necessary. 0.chunk.js:24766:5
The above error occurred in the <Example> component:
    in Example (at src/index.js:35)

TypeError: react_bootstrap_lib__WEBPACK_IMPORTED_MODULE_7___default.a is undefined
main.chunk.js:54:1
render
http://localhost:3000/static/js/main.chunk.js:54:1
finishClassComponent
http://localhost:3000/static/js/0.chunk.js:39068:26
updateClassComponent
http://localhost:3000/static/js/0.chunk.js:39032:14
beginWork
http://localhost:3000/static/js/0.chunk.js:39650:20
performUnitOfWork
http://localhost:3000/static/js/0.chunk.js:42205:16
workLoop
http://localhost:3000/static/js/0.chunk.js:42244:28
callCallback
http://localhost:3000/static/js/0.chunk.js:25107:13
invokeGuardedCallbackDev
http://localhost:3000/static/js/0.chunk.js:25156:11
invokeGuardedCallback
http://localhost:3000/static/js/0.chunk.js:25206:7
replayUnitOfWork
http://localhost:3000/static/js/0.chunk.js:41499:9
renderRoot
http://localhost:3000/static/js/0.chunk.js:42337:15
performWorkOnRoot
http://localhost:3000/static/js/0.chunk.js:43215:11
performWork
http://localhost:3000/static/js/0.chunk.js:43122:11
performSyncWork
http://localhost:3000/static/js/0.chunk.js:43095:7
requestWork
http://localhost:3000/static/js/0.chunk.js:42972:9
scheduleWork
http://localhost:3000/static/js/0.chunk.js:42765:9
scheduleRootUpdate
http://localhost:3000/static/js/0.chunk.js:43486:7
updateContainerAtExpirationTime
http://localhost:3000/static/js/0.chunk.js:43512:14
updateContainer
http://localhost:3000/static/js/0.chunk.js:43543:14
./node_modules/react-dom/cjs/react-dom.development.js/ReactRoot.prototype.render
http://localhost:3000/static/js/0.chunk.js:43825:7
legacyRenderSubtreeIntoContainer/<
http://localhost:3000/static/js/0.chunk.js:43979:13
unbatchedUpdates
http://localhost:3000/static/js/0.chunk.js:43360:14
legacyRenderSubtreeIntoContainer
http://localhost:3000/static/js/0.chunk.js:43975:9
render
http://localhost:3000/static/js/0.chunk.js:44039:16
./src/index.js
http://localhost:3000/static/js/main.chunk.js:133:1
__webpack_require__
http://localhost:3000/static/js/bundle.js:783:12
fn
http://localhost:3000/static/js/bundle.js:151:20
0
http://localhost:3000/static/js/main.chunk.js:151:18
__webpack_require__
http://localhost:3000/static/js/bundle.js:783:12
checkDeferredModules
http://localhost:3000/static/js/bundle.js:46:23
webpackJsonpCallback
http://localhost:3000/static/js/bundle.js:33:19
<anonymous>
http://localhost:3000/static/js/main.chunk.js:1:2