facebook / jscodeshift

A JavaScript codemod toolkit.
https://jscodeshift.com
MIT License
9.34k stars 481 forks source link

Getting missing `exportDefaultFrom` plugin error with `babel` parser, even though it's in `.babelrc` #303

Open nemoDreamer opened 5 years ago

nemoDreamer commented 5 years ago

Similar to #256 , in that I'm using Babel parser (not Babylon, because that doesn't actually result in all the modifications I'm expecting to see).

Using both local npx jscodeshift and global install.

The Transform is getting interpreted fine, it's just the Parser is having trouble with my sources (so #245 is not relevant)...

I just get this:

ERR src/components/WipeContainer/index.js Transformation error (This experimental syntax requires enabling the parser plugin: 'exportDefaultFrom' (1:7))
SyntaxError: This experimental syntax requires enabling the parser plugin: 'exportDefaultFrom' (1:7)
   at Object.raise (~/.config/yarn/global/node_modules/@babel/parser/lib/index.js:3834:17)
   at Object.expectPlugin (~/.config/yarn/global/node_modules/@babel/parser/lib/index.js:5147:18)
   at Object.parseExport (~/.config/yarn/global/node_modules/@babel/parser/lib/index.js:8209:12)

I've tried different --parser-config jscodeshift.config.json contents (as JSON, as module.exports, using "plugins": ["exportDefaultFrom"] vs the normal .babelrc format, etc), but the CLI help mentions that this is only for Flow or Babylon.

Here's my .babelrc (which I'd expect gets picked up by jscodeshift since I can't seem to supply a config any other way?):

{
  "presets": [
    "env",
    "react"
  ],
  "plugins": [
    "transform-object-rest-spread",
    "transform-export-default"
  ]
}

Babel transpilation works fine. It just seems that jscodeshift isn't picking up on my config?

nemoDreamer commented 5 years ago

Just FYI some results of switching parsers. (These are both dry-runs, so I'm not running the 2nd one on an already modified code-base!)

With --parser babel (ie the default) I get:

Processing 244 files...
Spawning 7 workers...
...
Results:
62 errors
144 unmodified
0 skipped
38 ok

The "fix" of switching to --parser babylon results in no errors, but only a tiny amount of the expected changes:

Processing 244 files...
Spawning 7 workers...
...
Results:
0 errors
239 unmodified
0 skipped
5 ok
cool4zbl commented 5 years ago

Same issue here..

fkling commented 5 years ago

babel is basically an old configuration to be compatible with babel v5. We should really just remove it.

The "fix" of switching to --parser babylon results in no errors, but only a tiny amount of the expected changes:

We should investigate why fewer files than you expect are picked up, but I'm not sure what is the best way to do this.

milesj commented 5 years ago

Is there a fix for this? This is quite blocking.

ElonVolo commented 2 years ago

If @fkling is recommending removing babel, should we be going in this direction?