gatsbyjs / gatsby

The best React-based framework with performance, scalability and security built in.
https://www.gatsbyjs.com
MIT License
55.27k stars 10.32k forks source link

Netlify build unexpected token in `gatsby-cli` in `init-starter.js` #26474

Closed MadMaxMcKinney closed 4 years ago

MadMaxMcKinney commented 4 years ago

I've been facing issues with Netlify and trying to build my site. I've had no issues for a solid year, then all of sudden I can't build. I decided to update my dependencies and now I'm getting an error in the gatsby package?

Error from Netlify:

10:53:30 AM: Build ready to start
10:53:32 AM: build-image version: 8e315e54bc4032a32e73290be556cde4f8348c12
10:53:32 AM: build-image tag: v2.8.2
10:53:32 AM: buildbot version: 45cd00068410d70db72c9672cdd014995488e12a
10:53:32 AM: Fetching cached dependencies
10:53:32 AM: Failed to fetch cache, continuing with build
10:53:32 AM: Starting to prepare the repo for build
10:53:32 AM: No cached dependencies found. Cloning fresh repo
10:53:32 AM: git clone git@github.com:MaxMcKinney/max-mckinney-gatsby
10:53:36 AM: Preparing Git Reference refs/heads/develop
10:53:37 AM: Starting build script
10:53:37 AM: Installing dependencies
10:53:38 AM: Downloading and installing node v8.17.0...
10:53:38 AM: Downloading https://nodejs.org/dist/v8.17.0/node-v8.17.0-linux-x64.tar.xz...
10:53:38 AM: #
10:53:38 AM: #
10:53:38 AM: #
10:53:38 AM: 1
10:53:38 AM: 0
10:53:38 AM: 0
10:53:38 AM: .
10:53:38 AM: 0
10:53:38 AM: %
10:53:38 AM: Computing checksum with sha256sum
10:53:38 AM: Checksums matched!
10:53:40 AM: Now using node v8.17.0 (npm v6.13.4)
10:53:41 AM: Attempting ruby version 2.3.6, read from environment
10:53:42 AM: Using ruby version 2.3.6
10:53:42 AM: Using PHP version 5.6
10:53:42 AM: Started restoring cached node modules
10:53:42 AM: Finished restoring cached node modules
10:53:42 AM: Installing NPM modules using NPM version 6.13.4
10:54:48 AM: > sharp@0.25.4 install /opt/build/repo/node_modules/sharp
10:54:48 AM: > (node install/libvips && node install/dll-copy && prebuild-install --runtime=napi) || (node-gyp rebuild && node install/dll-copy)
10:54:49 AM: info
10:54:49 AM: sharp
10:54:49 AM:  Downloading https://github.com/lovell/sharp-libvips/releases/download/v8.9.1/libvips-8.9.1-linux-x64.tar.gz
10:54:51 AM: > core-js@2.6.11 postinstall /opt/build/repo/node_modules/babel-runtime/node_modules/core-js
10:54:51 AM: > node -e "try{require('./postinstall')}catch(e){}"
10:54:52 AM: Thank you for using core-js ( https://github.com/zloirock/core-js ) for polyfilling JavaScript standard library!
10:54:52 AM: The project needs your help! Please consider supporting of core-js on Open Collective or Patreon: 
10:54:52 AM: > https://opencollective.com/core-js 
10:54:52 AM: > https://www.patreon.com/zloirock 
10:54:52 AM: Also, the author of core-js ( https://github.com/zloirock ) is looking for a good job -)
10:54:52 AM: > core-js@3.6.5 postinstall /opt/build/repo/node_modules/core-js
10:54:52 AM: > node -e "try{require('./postinstall')}catch(e){}"
10:54:52 AM: > core-js-pure@3.6.5 postinstall /opt/build/repo/node_modules/core-js-pure
10:54:52 AM: > node -e "try{require('./postinstall')}catch(e){}"
10:54:53 AM: > gatsby-telemetry@1.3.27 postinstall /opt/build/repo/node_modules/gatsby-telemetry
10:54:53 AM: > node src/postinstall.js || true
10:54:53 AM: > mozjpeg@6.0.1 postinstall /opt/build/repo/node_modules/mozjpeg
10:54:53 AM: > node lib/install.js
10:54:53 AM:   ✔ mozjpeg pre-build test passed successfully
10:54:53 AM: > pngquant-bin@5.0.2 postinstall /opt/build/repo/node_modules/pngquant-bin
10:54:53 AM: > node lib/install.js
10:54:54 AM:   ✔ pngquant pre-build test passed successfully
10:54:54 AM: > gatsby-cli@2.12.87 postinstall /opt/build/repo/node_modules/gatsby/node_modules/gatsby-cli
10:54:54 AM: > node scripts/postinstall.js
10:54:54 AM: > gatsby@2.24.47 postinstall /opt/build/repo/node_modules/gatsby
10:54:54 AM: > node scripts/postinstall.js
10:54:54 AM: > styled-components@4.4.1 postinstall /opt/build/repo/node_modules/styled-components
10:54:54 AM: > node ./scripts/postinstall.js || exit 0
10:54:55 AM: Use styled-components at work? Consider supporting our development efforts at https://opencollective.com/styled-components
10:55:00 AM: npm
10:55:00 AM:  WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.1.3 (node_modules/watchpack/node_modules/fsevents):
10:55:00 AM: npm
10:55:00 AM: WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.1.3: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
10:55:00 AM: npm
10:55:00 AM:  WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.13 (node_modules/fsevents):
10:55:00 AM: npm
10:55:00 AM: WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
10:55:00 AM: npm
10:55:00 AM: WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.1.3 (node_modules/chokidar/node_modules/fsevents):
10:55:00 AM: npm WARN
10:55:00 AM: notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.1.3: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
10:55:00 AM: added 2884 packages from 2122 contributors and audited 2892 packages in 76.777s
10:55:04 AM: 165 packages are looking for funding
10:55:04 AM:   run `npm fund` for details
10:55:04 AM: found 32 vulnerabilities (10 low, 22 high)
10:55:04 AM:   run `npm audit fix` to fix them, or `npm audit` for details
10:55:04 AM: NPM modules installed
10:55:05 AM: Started restoring cached go cache
10:55:05 AM: Finished restoring cached go cache
10:55:05 AM: Installing Go version 1.10
10:55:11 AM: unset GOOS;
10:55:11 AM: unset GOARCH;
10:55:11 AM: export GOROOT='/opt/buildhome/.gimme_cache/versions/go1.10.linux.amd64';
10:55:11 AM: export PATH="/opt/buildhome/.gimme_cache/versions/go1.10.linux.amd64/bin:${PATH}";
10:55:11 AM: go version >&2;
10:55:11 AM: export GIMME_ENV="/opt/buildhome/.gimme_cache/env/go1.10.linux.amd64.env"
10:55:11 AM: go version go1.10 linux/amd64
10:55:11 AM: Installing missing commands
10:55:11 AM: Verify run directory
10:55:11 AM: Executing user command: gatsby build
10:55:12 AM: /opt/build/repo/node_modules/gatsby/node_modules/gatsby-cli/lib/init-starter.js:121
10:55:12 AM:   } catch {
10:55:12 AM:           ^
10:55:12 AM: SyntaxError: Unexpected token {
10:55:12 AM:     at createScript (vm.js:80:10)
10:55:12 AM:     at Object.runInThisContext (vm.js:139:10)
10:55:12 AM:     at Module._compile (module.js:617:28)
10:55:12 AM:     at Object.Module._extensions..js (module.js:664:10)
10:55:12 AM:     at Module.load (module.js:566:32)
10:55:12 AM:     at tryModuleLoad (module.js:506:12)
10:55:12 AM:     at Function.Module._load (module.js:498:3)
10:55:12 AM:     at Module.require (module.js:597:17)
10:55:12 AM:     at require (internal/module.js:11:18)
10:55:12 AM:     at Object.<anonymous> (/opt/build/repo/node_modules/gatsby/node_modules/gatsby-cli/lib/create-cli.js:28:20)
10:55:12 AM: Skipping functions preparation step: no functions directory set
10:55:12 AM: Caching artifacts
10:55:12 AM: Started saving node modules
10:55:12 AM: Finished saving node modules
10:55:12 AM: Started saving pip cache
10:55:12 AM: Finished saving pip cache
10:55:12 AM: Started saving emacs cask dependencies
10:55:12 AM: Finished saving emacs cask dependencies
10:55:12 AM: Started saving maven dependencies
10:55:12 AM: Finished saving maven dependencies
10:55:12 AM: Started saving boot dependencies
10:55:12 AM: Finished saving boot dependencies
10:55:12 AM: Started saving go dependencies
10:55:13 AM: Finished saving go dependencies
10:55:17 AM: Error running command: Build script returned non-zero exit code: 7
10:55:17 AM: Failing build: Failed to build site
10:55:17 AM: failed during stage 'building site': Build script returned non-zero exit code: 7
10:55:17 AM: Finished processing build request in 1m45.424422215s

My package.js

{
  "name": "max-mckinney-gatsby",
  "description": "Max McKinney's personal portfolio website built with Gatsby, React, and GraphQL.",
  "version": "1.0.0",
  "author": "Max McKinney <maxgames101@gmail.com>",
  "dependencies": {
    "gatsby": "^2.24.47",
    "gatsby-image": "^2.4.16",
    "gatsby-plugin-google-analytics": "^2.3.13",
    "gatsby-plugin-layout": "^1.3.10",
    "gatsby-plugin-manifest": "^2.4.23",
    "gatsby-plugin-react-helmet": "^3.3.10",
    "gatsby-plugin-sharp": "^2.6.27",
    "gatsby-plugin-styled-components": "^3.3.10",
    "gatsby-remark-images": "^3.3.25",
    "gatsby-remark-images-medium-zoom": "^1.7.0",
    "gatsby-remark-responsive-iframe": "^2.4.12",
    "gatsby-source-filesystem": "^2.3.24",
    "gatsby-transformer-remark": "^2.8.28",
    "gatsby-transformer-sharp": "^2.5.13",
    "npm": "^6.14.7",
    "prop-types": "^15.7.2",
    "react": "^16.13.1",
    "react-dom": "^16.13.1",
    "react-helmet": "^5.2.1",
    "react-masonry-component": "^6.2.1",
    "styled-components": "^4.4.1",
    "typeface-barlow": "0.0.71",
    "typeface-roboto": "0.0.54",
    "typeface-source-sans-pro": "0.0.54"
  },
  "keywords": [
    "gatsby"
  ],
  "license": "MIT",
  "scripts": {
    "build": "gatsby build",
    "develop": "gatsby develop",
    "format": "prettier --write 'src/**/*.js'",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "devDependencies": {
    "prettier": "^1.19.1"
  },
  "repository": {
    "type": "git",
    "url": "https://github.com/MaxMcKinney/max-mckinney-gatsby"
  }
}

It builds locally just fine for me.

You can get the code here (under the develop branch): https://github.com/MaxMcKinney/max-mckinney-gatsby/tree/develop

aymanapatel commented 4 years ago

Yes. This was working last week. It is breaking all of a sudden.

Node version: 8.15.1

RyanRLong commented 4 years ago

Same.

Node version: 8.17.0 OS: ubuntu-xenial

MadMaxMcKinney commented 4 years ago

Okay so I managed to fix my issue. This may fix y'alls issues as well @SaltyCatFish @AymanArif. If you are using a newer version of Gatsby (maybe v2+, not sure) then it doesn't support older versions of Node. I believe it's node 10.x and newer that is needed. You need to update the version of node that Netlify is using.

There are some instructions here for how to do that (there are a few different ways):

https://docs.netlify.com/configure-builds/manage-dependencies/#node-js-and-javascript

I used the method of making a .node-version file in my root directory. In that file put only a single line with the version you want. I'm using the latest version: 12.18.2. Put only that in the file. You'll see that it works in the Netlify console output during the build process.

This may show other errors as the newer versions of Gatsby has better error logging, so keep an eye out for that as well.

actuallyReallyAlex commented 3 years ago

Additionally, if you don't want to create a new file in your workspace, you can just add an environment variable in your Netlify settings. The variable key must be NODE_VERSION and the value must be a version number - 10.15.2 for example. 👍