Node Functions and .babelrc

I have read on the docs for netlify-lambda that the package uses your .babelrc file if it exists (or indeed one exists in any parent dir!). If not, it creates it own minimal Babel config.

I don’t actually need to provide any babel config to netlify-lambda but I do have a .babelrc file (for Jest tests), which actually seems to break my Lambda if I allow netlify-lambda to read it. What’s the most correct/supported way to handle this situation?

I can’t think of any great solutions:

  • Delete the .babelrc file - now my testing breaks (and , of course, the .babelrc file could be for my main app too/instead, which would be meant for transpilation to the browser)
  • Rename the .babelrc file and update my non-Lambda build scripts to use that (if I can)
  • Move the babel config to package.json - this might actually be the best one, as long as the config isn’t too big
  • Dig out netlify-lambda's generated config and hardcode that in my .babelrc file if it can go alongside whatever’s in there - I don’t like this as it can end up going stale
  • Make a webpack config just for netlify-lambda and somehow configure the babel-loader to not look at the .babelrc file in the root (I imagine I’d still have to make a .babelrc file just for netlify-lambda and have to hardcode the current config (see last item for my issues with this). This is a solution I have seen mentioned around the internet.

Is there some other way to “turn off” just .babelrc detection and make netlify-lambda otherwise just use its default config.

The docs seem to suggest it can be turned off by passing --babelrc false, but it looks like doing so turns off the auto generation of the Babel config too (looking at the code certainly seems to suggests such: regardless of --babelrc value, it only generates the minimum sensible config iff no .babelrc exists).

I’d be willing to have a go at a PR on netlfiy-lambda to make the code mentioned above also generate the minimal config if --babelrc false as long as it’s seen that this is indeed supposed to happen.

Hi @alexrussell,

We’ve pinged our team and we’ll see what they say regarding whether or not we are accepting PR’s. One suggestion that I can suggest is seeing if you can use the Netlify CLI instead. Active development is happening on the Netlify CLI and eventually, it will be the recommended path for functions testing and deployment. Even now you can use it to build your functions.

FWIW in the end we were just able to move our babel config to babel.config.js and that did the trick.

But yeah, the issue here comes from the actual on-Netlify build process, not local dev. My local non-function app (same repo) needs a Babel config to do various things (currently only test env), but the functions don’t need the Babel config. But, the netlify-lambda build uses it anyway and finds an empty one (as it only has test env).

Maybe the Netlify CLI would work as you say in this case, but I’m not sure as I haven’t used it.