首页 > 解决方案 > jscodeshift PropTypes 到 proptypes 跳过节点模块中的所有文件

问题描述

我对后端反应设置完全陌生。一切都很顺利,直到我开始造型......我得到了这个

TypeError: Cannot read property 'object' of undefined
./node_modules/radium/lib/components/style.js
node_modules/radium/lib/components/style.js:23
  20 | displayName: 'Style',
  21 | 
  22 | propTypes: {
> 23 |   radiumConfig: _react.PropTypes.object,
     | ^  24 |   rules: _react.PropTypes.object,
  25 |   scopeSelector: _react.PropTypes.string
  26 | },

谷歌搜索后,我登陆了 jscodeshift ......所以我跑了

% jscodeshift --extensions js -t react-codemod/transforms/React-PropTypes-to-prop-types.js  node_modules/radium/lib/components/ --explicit-require=false
Processing 3 files...
Spawning 3 workers...
Sending 1 files to free worker...
Sending 1 files to free worker...
Sending 1 files to free worker...
All done.
Results:
0 errors
0 unmodified
3 skipped
0 ok
Time elapsed: 0.770seconds

我用谷歌搜索了一些,其他人在导入时遇到了问题,例如材料 UI,代码中没有返回,或者除了 js 文件。我什至删除了节点模块并重新安装了 npm 无济于事。我似乎无法为我的问题找到任何解决方案。

这是我的 package.JSON 依赖项...

"dependencies": {
    "@testing-library/jest-dom": "^4.2.4",
    "@testing-library/react": "^9.5.0",
    "@testing-library/user-event": "^7.2.1",
    "@types/react-burger-menu": "^2.6.1",
    "jscodeshift": "^0.9.0",
    "prop-types": "^15.7.2",
    "radium": "^0.26.0",
    "react": "^15.6.2",
    "react-burger-menu": "^1.12.0",
    "react-dom": "^15.6.2",
    "react-scripts": "3.4.1",
    "yarn": "^1.22.4"
  },

任何帮助深表感谢。ps:我愿意完全重置整个项目。

标签: node.jsnpmpackage.jsonreact-proptypesjscodeshift

解决方案


重新安装一切解决了这个问题。

我认为我出错的地方可能是:1.安装或重新安装版本不兼容的软件包,即不同版本的 react-dom 和 react 等。2.一次尝试太多东西......

对未来谷歌员工的建议:慢慢来,尤其是在转换为 TS 时。确保基本的反应应用程序正在运行。然后在迁移到 TS 时逐步转换或添加您需要的其他模块。

一切顺利!


推荐阅读