Multiple syntax transformation errors with babylon.
See original GitHub issueHello,
I’m relatively new to jscodeshift, babel, etc. so I hope you can bear with me while I try to explain my problem.
A bit of background: I wrote a react-native application which I attempted to upgrade from 0.34.1 to the latest version using react-native-git-upgrade. Up until then, everything was working fine I had never actually interacted with babel, but I had run a jscodeshift called https://github.com/sibelius/codemod-RN24-to-RN25 to fix the importing error that is pretty well known. It worked great.
After I attempted the update I wasn’t sure how to fix my git conflicts so I backpedalled and checked out all my uncommitted changes, deleted any generated files (.babelrc, .flow) and then removed my node_modules folder and ran npm install
again. At this point I was getting the import error again and went to run the handy codemod but this time I got numerous syntax errors.
I’m currently unable to get past these syntax errors. Any help at all would be greatly appreciated. Some of my stacktrace:
Processing 31100 files...
Spawning 3 workers...
Sending 50 files to free worker...
Sending 50 files to free worker...
Sending 50 files to free worker...
ERR ../node_modules/detect-newline/cli.js Transformation error
SyntaxError: 'return' outside of function (30:4)
at Parser.pp.raise (/usr/local/lib/node_modules/jscodeshift/node_modules/babylon/lib/parser/location.js:24:13)
at Parser.pp.parseReturnStatement (/usr/local/lib/node_modules/jscodeshift/node_modules/babylon/lib/parser/statement.js:275:10)
at Parser.pp.parseStatement (/usr/local/lib/node_modules/jscodeshift/node_modules/babylon/lib/parser/statement.js:89:19)
at Parser.parseStatement (/usr/local/lib/node_modules/jscodeshift/node_modules/babylon/lib/plugins/flow.js:655:22)
at Parser.pp.parseBlock (/usr/local/lib/node_modules/jscodeshift/node_modules/babylon/lib/parser/statement.js:442:21)
at Parser.pp.parseStatement (/usr/local/lib/node_modules/jscodeshift/node_modules/babylon/lib/parser/statement.js:105:19)
at Parser.parseStatement (/usr/local/lib/node_modules/jscodeshift/node_modules/babylon/lib/plugins/flow.js:655:22)
at Parser.pp.parseIfStatement (/usr/local/lib/node_modules/jscodeshift/node_modules/babylon/lib/parser/statement.js:268:26)
at Parser.pp.parseStatement (/usr/local/lib/node_modules/jscodeshift/node_modules/babylon/lib/parser/statement.js:87:19)
at Parser.parseStatement (/usr/local/lib/node_modules/jscodeshift/node_modules/babylon/lib/plugins/flow.js:655:22)
Sending 50 files to free worker...
Sending 50 files to free worker...
ERR ../node_modules/errno/cli.js Transformation error
SyntaxError: 'return' outside of function (8:2)
at Parser.pp.raise (/usr/local/lib/node_modules/jscodeshift/node_modules/babylon/lib/parser/location.js:24:13)
at Parser.pp.parseReturnStatement (/usr/local/lib/node_modules/jscodeshift/node_modules/babylon/lib/parser/statement.js:275:10)
at Parser.pp.parseStatement (/usr/local/lib/node_modules/jscodeshift/node_modules/babylon/lib/parser/statement.js:89:19)
at Parser.parseStatement (/usr/local/lib/node_modules/jscodeshift/node_modules/babylon/lib/plugins/flow.js:655:22)
at Parser.pp.parseIfStatement (/usr/local/lib/node_modules/jscodeshift/node_modules/babylon/lib/parser/statement.js:268:26)
at Parser.pp.parseStatement (/usr/local/lib/node_modules/jscodeshift/node_modules/babylon/lib/parser/statement.js:87:19)
at Parser.parseStatement (/usr/local/lib/node_modules/jscodeshift/node_modules/babylon/lib/plugins/flow.js:655:22)
at Parser.pp.parseTopLevel (/usr/local/lib/node_modules/jscodeshift/node_modules/babylon/lib/parser/statement.js:30:21)
at Parser.parse (/usr/local/lib/node_modules/jscodeshift/node_modules/babylon/lib/parser/index.js:70:17)
at Object.parse (/usr/local/lib/node_modules/jscodeshift/node_modules/babylon/lib/index.js:45:50)
Sending 50 files to free worker...
Sending 50 files to free worker...
Sending 50 files to free worker...
Sending 50 files to free worker...
My versions:
react-native-cli: 1.0.0
react-native: 0.34.1
node: v6.3.1
Thank you
Issue Analytics
- State:
- Created 7 years ago
- Comments:5 (2 by maintainers)
Top GitHub Comments
@fkling makes sense. Thanks for the info. Haven’t been able to get past these syntax errors. I dont really have any info to give you regarding my code because my code was running just fine until I tried to upgrade react-native and run the jscodeshift. I’ll have to do more research on my end to figure this out.
Thanks for taking the time. Cheers
Codemods are supposed to be run on code that you wrote, not on third party dependencies.
As for your other error, there isn’t much we can say about it without actually seeing your code. You could try passing
--parser="babylon"
. By default jscodeshift uses an older version of babylon that doesn’t support all flow syntax constructs.