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

gatsby build issues - likely async related #3931

Closed
gbailey4 opened this issue Feb 8, 2018 · 8 comments
Closed

gatsby build issues - likely async related #3931

gbailey4 opened this issue Feb 8, 2018 · 8 comments

Comments

@gbailey4
Copy link

gbailey4 commented Feb 8, 2018

Description

Upon running gatsby build the build process crashes on the minify js portion.

Environment

Gatsby version:
1.9.158
Node.js version:
8.9.1
Operating System:
macOS 10.13.3

File contents (if changed):

gatsby-config.js: no change
package.json: no change
gatsby-node.js: no change
gatsby-browser.js: no change
gatsby-ssr.js: no change

Actual result

error thrown:

  SyntaxError: Unexpected token operator «*», expected punc «(» [./src/components/CreateLuncher.js:50,19]

Expected behavior

successful build of project

Steps to reproduce

1. Build the repo here:
https://github.com/gbailey4/SimpleLunch

2.
The specific file that is throwing the error is here:
https://github.com/gbailey4/SimpleLunch/blob/master/src/components/CreateLuncher.js

...

@m-allanson
Copy link
Contributor

m-allanson commented Feb 9, 2018

@gbailey4 I had a go at fixing this, based on @Kalcode's comment .

First install a couple of babel plugins:
npm i babel-plugin-transform-regenerator

Then add the following to your gatsby-node.js file:

 exports.modifyBabelrc = ({ babelrc }) => ({
    ...babelrc,
    plugins: babelrc.plugins.concat(['transform-regenerator']),
  })

That left the build with a different error, which looks like it's related to trying to run browser code in Node. I'm not familiar with Apollo but if it should be client-only code, you'll need to check you're in a browser before running it. There's a bit more info at https://www.gatsbyjs.org/docs/debugging-html-builds/

@gbailey4
Copy link
Author

gbailey4 commented Feb 9, 2018

Thank you very much. I actually forgot about the other error, but do have a fix for that. I will trust your fix soon and hope it goes as predicted!

@gbailey4
Copy link
Author

OK, so I was able to get it working. I fixed the issue with Apollo through some process.browser handling. Then, however, I needed to add the module 'regenerator-runtime' in dev dependancies and in the file with an async function import 'regenerator-runtime/runtime';

That worked upon doing gatsby build! Thanks so much for your help, this was a huge help.

@gscottqueen
Copy link

gscottqueen commented Jun 30, 2018

Had the same alert with async/await, @m-allanson is right on with the transform-regenerator recommendation.

UPDATED: To follow back up on a related issue when implementing...

The above fix worked when running 'gatsby build' for production, but I ran into another console error running 'gatsby develop'

"Uncaught (in promise) ReferenceError: regeneratorRuntime is not defined"

to resolve, I included babel-plugin-transform-runtime as a dev dependincy and concat it with our generator.

exports.modifyBabelrc = ({ babelrc }) => ({
  ...babelrc,
  plugins: babelrc.plugins.concat(
    ['transform-regenerator'],
    ['transform-runtime']
  ),
})

@cdock1029
Copy link

cdock1029 commented Aug 13, 2018

This is the simplest solution I could find to solve both dev and prod which did not require import-ing anything in code:

My .babelrc file:

{
  "env": {
    "development": {
      "plugins": ["transform-async-to-generator"] // also works, but older: "syntax-async-functions"
    },
    "production": {
      "plugins": ["transform-regenerator", "transform-runtime"]
    }
  }
}

@imcodingideas
Copy link
Contributor

I have my fix similar to @gscottqueen but in gatsby-browser.js I added

exports.onClientEntry = () => {
  require('babel-polyfill')
}

joshribakoff added a commit to joshribakoff/portfolio that referenced this issue Oct 8, 2018
joshribakoff added a commit to joshribakoff/portfolio that referenced this issue Oct 8, 2018
This reverts commit fe06a79.

Revert "remove gatsby-source-youtube"

This reverts commit cb4c1b6.

Revert "switch gitlab ci to yarn"

This reverts commit c3bbe2b.

Revert "disable cache"

This reverts commit f38b2e1.

Revert "upgrade gatsby to 2.0"

This reverts commit 9c9e2cf.

Revert "gatsbyjs/gatsby#3931 (comment)"

This reverts commit 5e69385.

Revert "bump gatbsy cli tools"

This reverts commit c886660.

Revert "bump node to LTS"

This reverts commit d3a66f2.

Revert "adds videos page"

This reverts commit 235a665.
@hassanshaikley
Copy link

hassanshaikley commented Nov 28, 2018

hey all, I seem to be running into something similar? I am using async/awaits in some plugins.

Got these errors:

screenshot_20181128_165820

So I tried:

exports.onCreateBabelConfig = ({ actions }, pluginOptions) => {
    actions.setBabelPlugin({
        name: `@babel/plugin-transform-regenerator`
    })
    actions.setBabelPlugin({
        name: `@babel/plugin-transform-runtime`
    })
}

And the errors still look exactly the same!

@peter-mouland
Copy link
Contributor

@hassanshaikley this looks more like a 404. what is the response from that js url?

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

No branches or pull requests

7 participants