question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Multiple syntax transformation errors with babylon.

See original GitHub issue

Hello,

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:closed
  • Created 7 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
jaredtibscommented, Feb 8, 2017

@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

1reaction
fklingcommented, Feb 6, 2017

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Handle syntax errors from babylon that need a plugin #6205
exportExtensions has two transforms, namely @babel/plugin-proposal-export-namespace and @babel/plugin-proposal-export-default , linked to it.
Read more >
babel/parser
The Babel parser (previously Babylon) is a JavaScript parser used in Babel. The latest ECMAScript version enabled by default (ES2020). Comment attachment.
Read more >
Forest with Colliders - Questions - Babylon.js Forum
When I try to create an instance of a mesh that has multiple materials I can only create an instance of one part...
Read more >
Is it possible to convert Babylon parsed AST back to source ...
@Bergi, I was trying to transform AST back to it's original form (ES2015 synatx), not transpile it into older syntax.
Read more >
SQL transformation fails when it has multiple SQLs separated ...
When ran data preview on SQL Transformation in version 10.1.1 HotFix 2, it failed with the following error: [Informatica][ODBC SQL Server ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found