Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doesn't work if config is in "babel.config.js" file #18

Open
serhiipalash opened this issue Nov 14, 2018 · 4 comments
Open

Doesn't work if config is in "babel.config.js" file #18

serhiipalash opened this issue Nov 14, 2018 · 4 comments

Comments

@serhiipalash
Copy link

serhiipalash commented Nov 14, 2018

  • babel-plugin-codegen version: 3.0.0
  • nodeversion: 10.13.0
  • npm (or yarn) version: 1.12.3

Plugin doesn't work if your Babel config is in babel.config.js, but all works fine if it is in .babelrc

babel.config.js

module.exports = function() {
  return {
    presets: ['babel-preset-expo'],
    plugins: ['codegen'],
  }
}

.babelrc

{
  "presets": ["babel-preset-expo"],
  "plugins": [
    "codegen"
  ]
}

What you did:

// @codegen

module.exports = '
  module.exports = []
'

What happened:

When I use babel.config.js, I get export from module as string "module.exports = []", like there is no top comment "// @codegen".

When I use .babelrc, I get empty array as export from module, as it should be.

Reproduction repository:

https://github.com/serhiipalash/test-babel-codegen

Latest Expo has babel config in babel.config.js, and I don't want to change it as it is the standard for all future releases.

@kentcdodds
Copy link
Owner

Hmmm... This is very odd. I'm not sure why it would make any difference. Could you do a little digging to figure out what's wrong here? Thanks!

@wamry
Copy link

wamry commented Jul 17, 2019

Same happens with me when im using plugin "transform-remove-console"
I fixed it by reseting cache

@sylvanaar
Copy link

sylvanaar commented Aug 16, 2020

This seems like a stale issue. I am not having this problem on v4 of the plugin. Though my module.exports is not a function

module.exports = {
    presets: ["module:metro-react-native-babel-preset", "module:react-native-dotenv"],
    plugins: ["codegen"],
};

@loynoir
Copy link
Contributor

loynoir commented Aug 31, 2021

Not sure if same kind of babel.config.js issue, but mine babel.config.js issue fixed by

#43

Current code using wrong signature hidden below magic linter comment.
So, some context got lost but without reported.
Maybe some plugins just not effected by that lost context.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants