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

webpack picks up .babelrc on netlify deploy but not locally? #152

Closed
omonk opened this issue May 16, 2019 · 6 comments
Closed

webpack picks up .babelrc on netlify deploy but not locally? #152

omonk opened this issue May 16, 2019 · 6 comments
Labels

Comments

@omonk
Copy link
Contributor

omonk commented May 16, 2019

Whilst trying to deploy on Netlify I get an error relating to babel-preset-gatsby being loaded by webpack.

4:51:44 PM: Module build failed (from /opt/build/repo/node_modules/babel-loader/lib/index.js):
4:51:44 PM: Error: [BABEL] /opt/build/repo/src/functions/meetup.js: `babel-preset-gatsby` has been loaded, which consumes config generated by the Gatsby CLI. Set `NODE_ENV=test` to bypass, or run `gatsby build` first. (While processing: "/opt/build/repo/node_modules/babel-preset-gatsby/index.js")

Makes total sense but can anyone tell me why I can't replicate this locally?

I've tried setting NODE_ENV to 'production' locally but not getting it.

"build": "run-p build:**",
"build:app": "gatsby build",
"build:lambda": "netlify-lambda -c webpack.functions.js build src/functions",

webpack config:

const webpack = require('webpack')
const nodeExternals = require('webpack-node-externals')

module.exports = {
  externals: [nodeExternals()],
  mode: 'production',
  plugins: [new webpack.DefinePlugin({ 'global.GENTLY': false })]
}

.babelrc

{
  "presets": ["babel-preset-gatsby"],
  "env": {
    "test": {
      "plugins": ["require-context-hook"]
    }
  }
}

any ideas?

@swyxio
Copy link
Contributor

swyxio commented May 16, 2019

i gotta admit the babel resolution logic might have some mismatch here vs what netlify does in production. no time to look into this right now but thank you for filing and i hope someone can dive in.

this is possibly (but not definitely) the relevant code https://github.com/netlify/netlify-lambda/blob/master/lib/build.js#L18-L32

@omonk
Copy link
Contributor Author

omonk commented May 17, 2019

What kind of things do you think would be different in local vs netlify?

@omonk
Copy link
Contributor Author

omonk commented May 17, 2019

For reference this issue touches on the same thing I'm up against: #34

What I'm experiencing now is that the webpack merge produces a rules config that I'm not sure will play nicely with what I'm trying to do, effectively having babel-loader configured twice?

Using the config from #34

webpack.functions.js

module.exports = {
  externals: [nodeExternals()],
  mode: 'production',
  plugins: [new webpack.DefinePlugin({ 'global.GENTLY': false })],
  module: {
    rules: [
      {
        test: /\.js?$/,
        exclude: /(node_modules|bower_components)/,
        use: {
          loader: 'babel-loader',
          options: {
            babelrc: false
          }
        }
      }
    ]
  }
}

goes on to produce these rules in the final webpack config

final module section in webpack config after merge:

....
"module": {
    "rules": [
      {
        "test": {},
        "exclude": {},
        "use": {
          "loader": "/Users/ollie/sites/netlify-lambda/node_modules/babel-loader/lib/index.js",
          "options": {
            "cacheDirectory": true
          }
        }
      },
      {
        "test": {},
        "exclude": {},
        "use": {
          "loader": "babel-loader",
          "options": {
            "babelrc": false
          }
        }
      }
    ]
  },
....

@swyxio
Copy link
Contributor

swyxio commented May 17, 2019

thank you @omonk 🙇🏼‍♂️

@swyxio
Copy link
Contributor

swyxio commented May 18, 2019

we added an option in v1.4.10 in PR #154

@stale
Copy link

stale bot commented Jul 17, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Jul 17, 2019
@swyxio swyxio closed this as completed Jul 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants