对于我当前的项目,我使用的是React,Redux和Typescript。这是我的package.json依赖项。
"dependencies": {
"@types/lodash": "^4.14.105",
"@types/react-router": "^4.0.23",
"@types/react-router-dom": "^4.2.5",
"axios": "^0.18.0",
"lodash": "^4.17.5",
"prop-types": "^15.6.1",
"react": "^16.2.0",
"react-dom": "^16.2.0",
"react-redux": "^5.0.7",
"react-router-dom": "^4.2.2",
"redux": "^3.7.2",
"redux-logger": "^3.0.6",
"redux-thunk": "^2.2.0",
"thunk": "^0.0.1"
},
"devDependencies": {
"@types/prop-types": "^15.5.2",
"@types/react": "^16.0.40",
"@types/react-dom": "^16.0.4",
"@types/react-redux": "^5.0.15",
"@types/redux": "^3.6.0",
"@types/redux-logger": "^3.0.5",
"@types/redux-thunk": "^2.1.0",
"awesome-typescript-loader": "^4.0.1",
"babel-cli": "^6.26.0",
"babel-loader": "^7.1.4",
"babel-preset-env": "^1.6.1",
"babel-preset-react": "^6.24.1",
"babel-register": "^6.26.0",
"chai": "^4.1.2",
"css-loader": "^0.28.10",
"enzyme": "^3.3.0",
"enzyme-adapter-react-16": "^1.1.1",
"html-webpack-plugin": "^3.1.0",
"mocha": "^5.0.4",
"node-sass": "^4.8.1",
"react-test-renderer": "^16.2.0",
"sass-loader": "^6.0.7",
"source-map-loader": "^0.2.3",
"style-loader": "^0.20.3",
"tslint": "^5.9.1",
"tslint-config-airbnb": "^5.8.0",
"typescript": "^2.7.2",
"webpack": "^4.1.1",
"webpack-cli": "^2.0.11",
"webpack-dev-server": "^3.1.1",
"webpack-merge": "^4.1.2"
}
我没有使用babel进行编译,所以请忽略babel依赖项,因为我很快就会删除它们。我正在使用react-redux最新版本,但我在控制台中收到此错误。
PropTypes.js?721c:3 Uncaught TypeError: Cannot read property 'shape' of undefined
at eval (PropTypes.js?721c:3)
at Object../node_modules/react-redux/es/utils/PropTypes.js (bundle.js:970)
at __webpack_require__ (bundle.js:20)
at eval (Provider.js?fa28:9)
at Object../node_modules/react-redux/es/components/Provider.js (bundle.js:850)
at __webpack_require__ (bundle.js:20)
at eval (index.js?a7ec:1)
at Object../node_modules/react-redux/es/index.js (bundle.js:958)
at __webpack_require__ (bundle.js:20)
at eval (index.tsx?d986:5)
我偶然发现了这个问题https://github.com/reactjs/react-redux/issues/822,但这似乎并没有解决我的问题。您可以在此处查看他们的代码https://unpkg.com/react-redux@5.0.7/es/utils/PropTypes.js
更新:我弄错了,我已经更改了tsconfig.json
"module": "commonjs",
至"module": "es6",