1

在使用流的 javascript 项目中运行时遇到错误。

npx react-codemod 重命名-不安全-生命周期

如何让这个 codemod 正常运行。这是将项目的 React 版本升级到 16.9+ 所必需的

 ERR src\datatypes\Mammografie.js Transformation error (Cannot read property 'process' of undefined)
TypeError: Cannot read property 'process' of undefined
    at process (C:\Users\guus-\AppData\Roaming\npm-cache\_npx\37416\node_modules\react-codemod\node_modules\flow-parser/flow_parser.js:308:70)
    at Object.<anonymous> (C:\Users\guus-\AppData\Roaming\npm-cache\_npx\37416\node_modules\react-codemod\node_modules\flow-parser/flow_parser.js:2:2)
    at Module._compile (internal/modules/cjs/loader.js:956:30)
    at Module._compile (C:\Users\guus-\AppData\Roaming\npm-cache\_npx\37416\node_modules\react-codemod\node_modules\pirates\lib\index.js:99:24)
    at Module._extensions..js (internal/modules/cjs/loader.js:973:10)
    at Object.newLoader [as .js] (C:\Users\guus-\AppData\Roaming\npm-cache\_npx\37416\node_modules\react-codemod\node_modules\pirates\lib\index.js:104:7)
    at Module.load (internal/modules/cjs/loader.js:812:32)
    at Function.Module._load (internal/modules/cjs/loader.js:724:14)
    at Module.require (internal/modules/cjs/loader.js:849:19)
    at require (internal/modules/cjs/helpers.js:74:18)
All done.
Results:
278 errors
0 unmodified
0 skipped
0 ok
Time elapsed: 26.769seconds
4

1 回答 1

0

使用 jscodeshift 和--no-babel标志为我工作,而不是 npx 包。似乎 npx react-codemod 现在不接受任何标志:

jscodeshift --no-babel --parser=flow -t /path/to/react-codemod/transforms/class.js /path/to/src
于 2020-01-27T11:34:11.740 回答