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 + storybook + async/await + NODE_ENV=production == FAIL #13176

Closed
i8ramin opened this issue Apr 6, 2019 · 3 comments
Closed

Gatsby + storybook + async/await + NODE_ENV=production == FAIL #13176

i8ramin opened this issue Apr 6, 2019 · 3 comments
Assignees

Comments

@i8ramin
Copy link
Contributor

i8ramin commented Apr 6, 2019

Description

For some reason, the following combination of things causes the Gatsby build to fail:

  • async/await code
  • @storybook packages
  • NODE_ENV=production

Steps to reproduce

Repo with basic Gatsby setup + @storybook devDependencies + async/await code:
https://github.com/i8ramin/gatsby-test-prod-async

git clone https://github.com/i8ramin/gatsby-test-prod-async
cd gatsby-test-prod-async
NODE_ENV=production yarn install --ignore-optional
NODE_ENV=production yarn build

Possibly related GH issues

Expected result

Expect the site to build just fine. Which it does if you do any of the following:

  • remove the async/await code, it builds just fine.
  • remove the @storybook from devDependencies, it builds just fine.
  • add @storybook modules to dependencies, it builds just fine (after issuing rm -rf node_modules && NODE_ENV=production yarn install --ignore-optional)

Actual result

error Generating JavaScript bundles failed


  Error: ./src/pages/index.js
  Module not found: Error: Can't resolve 'regenerator-runtime/runtime' in '/Users/home/tmp/gatsby-test-prod-  async/src/pages'
  resolve 'regenerator-runtime/runtime' in '/Users/home/tmp/gatsby-test-prod-async/src/pages'
    Parsed request is a module
    using description file: /Users/home/tmp/gatsby-test-prod-async/package.json (relative path: ./src/pages)      Field 'browser' doesn't contain a valid alias configuration
      resolve as module
        /Users/home/tmp/gatsby-test-prod-async/src/pages/

Environment

System:
OS: macOS 10.14.3
CPU: (8) x64 Intel(R) Core(TM) i7-7820HQ CPU @ 2.90GHz
Shell: 5.7.1 - /usr/local/bin/zsh
Binaries:
Node: 11.6.0 - ~/.nvm/versions/node/v11.6.0/bin/node
Yarn: 1.12.3 - /usr/local/bin/yarn
npm: 6.5.0-next.0 - ~/.nvm/versions/node/v11.6.0/bin/npm
Languages:
Python: 2.7.15 - /usr/local/bin/python
Browsers:
Chrome: 73.0.3683.103
Firefox: 54.0.1
Safari: 12.0.3
npmPackages:
gatsby: ^2.3.5 => 2.3.14
gatsby-plugin-root-import: 2.0.5 => 2.0.5

Related issue created in the @storybook repo: storybookjs/storybook#6443

@i8ramin
Copy link
Contributor Author

i8ramin commented Apr 6, 2019

Btw, adding regenerator-runtime to dependencies also solves the problem. But its still not clear to me why this is happening in the first place.

Also, does Gatsby need or care about NODE_ENV=production in any way? If gatsby build always does a production build, I guess there is really no reason to set NODE_ENV=production, right?

@trevorlitsey
Copy link
Contributor

Hi @i8ramin, thanks for the sample repo. On my local machine, I am unfortunately not able to reproduce the error. The build works fine for me.

That said, I'm not sure that one should necessarily expect a build to be successful if only production dependencies are installed. NODE_ENV=production yarn install, as you may know, only installs packages listed in dependencies, and ignores packages listed in devDependencies. I'm not an expert on the gatsby build scripts, but there are a handful of dependencies listed as devDependencies. Those libraries are likely needed for the build process, but might not contain any code meant to be shipped to the browser.

https://docs.npmjs.com/cli/install

@trevorlitsey trevorlitsey self-assigned this Apr 6, 2019
@trevorlitsey
Copy link
Contributor

Hi @i8ramin, sorry, I just realized I provided a link to the NPM docs while your reproduction steps use Yarn. I just cloned the repo again and still no issues with the build when using Yarn.

Same treatment in regards to devDependencies, but here's the relevant Yarn docs on yarn install:
https://yarnpkg.com/en/docs/cli/install#toc-yarn-install-production-true-false

Closing this issue as I believe the Gatsby code is working as expected.

Best!

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

2 participants