Gatsby: TypeError: Cannot read property 'minify' of undefined at minify with terser plugin

Created on 2 Feb 2019  ยท  7Comments  ยท  Source: gatsbyjs/gatsby

Description

Production build doesn't build, but dev build is good

Steps to reproduce

Just run gatsby build

P. S. This is after update
Part of yarn.lock before update while everything's works (good prod build without any errors)

terser@^3.8.1:
  version "3.14.1"
  resolved "https://registry.yarnpkg.com/terser/-/terser-3.14.1.tgz#cc4764014af570bc79c79742358bd46926018a32"
  integrity sha512-NSo3E99QDbYSMeJaEk9YW2lTg3qS9V0aKGlb+PlOrei1X02r1wSBHCNX/O+yeTRFSWPKPIGj6MqvvdqV4rnVGw==
  dependencies:
    commander "~2.17.1"
    source-map "~0.6.1"
    source-map-support "~0.5.6"

After update we have this (errors in "Environment" section below)

terser@^3.8.1:
  version "3.16.0"
  resolved "https://registry.yarnpkg.com/terser/-/terser-3.16.0.tgz#04028e6e5da461d91691cedd75fa53a17f2f20d9"
  integrity sha512-Ua8BhyibmsQBFXDZZ3Es7GASB2yFrQJr0jgAlZK1FBLbFarrHoCuMHPCro5MbX4jidcaFGiV+uTc3wxodmGjUg==
  dependencies:
    commander "~2.17.1"
    source-map "~0.6.1"
    source-map-support "~0.5.9"

Expected result

Prod build

Actual result

Prod build with error on js stage

Environment

gatsby info --clipboard
``` ubuntu@ubuntu ๎‚ฐ ~/pet/podabed.org ๎‚ฐ ๎‚  sourceV2 โ—โœš ๎‚ฐ gatsby info --clipboard

System:
OS: Linux 4.4 Ubuntu 16.04.5 LTS (Xenial Xerus)
CPU: (4) x64 AMD Athlon(tm) X4 860K Quad Core Processor
Shell: 5.1.1 - /usr/bin/zsh
Binaries:
Node: 10.15.1 - ~/.nvm/versions/node/v10.15.1/bin/node
Yarn: 1.13.0 - ~/.nvm/versions/node/v10.15.1/bin/yarn
npm: 6.7.0 - ~/.nvm/versions/node/v10.15.1/bin/npm
Languages:
Python: 2.7.12 - /usr/bin/python
Browsers:
Chrome: 72.0.3626.81
Firefox: 65.0
npmPackages:
gatsby: ^2.0.111 => 2.0.111
gatsby-image: ^2.0.29 => 2.0.29
gatsby-plugin-i18n: ^1.0.1 => 1.0.1
gatsby-plugin-manifest: ^2.0.17 => 2.0.17
gatsby-plugin-offline: ^2.0.22 => 2.0.22
gatsby-plugin-postcss: ^2.0.5 => 2.0.5
gatsby-plugin-react-helmet: ^3.0.6 => 3.0.6
gatsby-plugin-sharp: ^2.0.20 => 2.0.20
gatsby-plugin-typescript: ^2.0.6 => 2.0.6
gatsby-remark-images: ^3.0.3 => 3.0.3
gatsby-source-filesystem: ^2.0.20 => 2.0.20
gatsby-transformer-remark: ^2.2.3 => 2.2.3
gatsby-transformer-sharp: ^2.1.13 => 2.1.13
npmGlobalPackages:
gatsby-cli: 2.4.8

`gatsby build --verbose`
```/home/ubuntu/.nvm/versions/node/v10.15.1/bin/node /home/ubuntu/.nvm/versions/node/v10.15.1/lib/node_modules/yarn/bin/yarn.js run startProd
yarn run v1.13.0
$ yarn run clean && yarn run build && gatsby serve --verbose
$ rm -rf ./.cache/* && rm -rf ./public/*
$ gatsby build --verbose
verbose 0.657 set gatsby_log_level: "verbose"
verbose 0.66 set gatsby_executing_command: "build"
verbose 0.661 loading local command from: /home/ubuntu/pet/podabed.org/node_modules/gatsby/dist/commands/build.js
verbose 1.946 running command: build
success open and validate gatsby-configs โ€” 0.014 s
success load plugins โ€” 0.295 s
success onPreInit โ€” 0.968 s
success delete html and css files from previous builds โ€” 0.006 s
success initialize cache โ€” 0.007 s
success copy gatsby files โ€” 0.146 s
success onPreBootstrap โ€” 0.009 s
success source and transform nodes โ€” 0.487 s
success building schema โ€” 0.322 s
success createPages โ€” 0.089 s
success createPagesStatefully โ€” 0.041 s
success onPreExtractQueries โ€” 0.003 s
success update schema โ€” 0.218 s
success extract queries from components โ€” 0.143 s
success run graphql queries โ€” 3.359 s โ€” 54/54 16.08 queries/second
success write out page data โ€” 0.003 s
success write out redirect data โ€” 0.000 s


info bootstrap finished - 85.671 s

success onPostBootstrap โ€” 0.005 s

error Generating JavaScript bundles failed


  Error: 0-605ebb314b340a3fdb75.js from Terser
  TypeError: Cannot read property 'minify' of undefined
      at minify (/home/ubuntu/pet/podabed.org/node_modules/terser-webpack-plugin  /dist/minify.js:175:23)
      at module.exports (/home/ubuntu/pet/podabed.org/node_modules/terser-webpac  k-plugin/dist/worker.js:13:40)
      at handle (/home/ubuntu/pet/podabed.org/node_modules/worker-farm/lib/child  /index.js:44:8)
      at process.<anonymous> (/home/ubuntu/pet/podabed.org/node_modules/worker-f  arm/lib/child/index.js:51:3)
      at process.emit (events.js:189:13)
      at emit (internal/child_process.js:820:12)
      at process._tickCallback (internal/process/next_tick.js:63:19)



  Error: app-9f97c9fcff725b10d2d8.js from Terser
  TypeError: Cannot read property 'minify' of undefined
      at minify (/home/ubuntu/pet/podabed.org/node_modules/terser-webpack-plugin  /dist/minify.js:175:23)
      at module.exports (/home/ubuntu/pet/podabed.org/node_modules/terser-webpac  k-plugin/dist/worker.js:13:40)
      at handle (/home/ubuntu/pet/podabed.org/node_modules/worker-farm/lib/child  /index.js:44:8)
      at process.<anonymous> (/home/ubuntu/pet/podabed.org/node_modules/worker-f  arm/lib/child/index.js:51:3)
      at process.emit (events.js:189:13)
      at emit (internal/child_process.js:820:12)
      at process._tickCallback (internal/process/next_tick.js:63:19)



  Error: component---node-modules-gatsby-plugin-offline-app-shell-js-91bd728d3d0  b9d6d10d8.js from Terser
  TypeError: Cannot read property 'minify' of undefined
      at minify (/home/ubuntu/pet/podabed.org/node_modules/terser-webpack-plugin  /dist/minify.js:175:23)
      at module.exports (/home/ubuntu/pet/podabed.org/node_modules/terser-webpac  k-plugin/dist/worker.js:13:40)
      at handle (/home/ubuntu/pet/podabed.org/node_modules/worker-farm/lib/child  /index.js:44:8)
      at process.<anonymous> (/home/ubuntu/pet/podabed.org/node_modules/worker-f  arm/lib/child/index.js:51:3)
      at process.emit (events.js:189:13)
      at emit (internal/child_process.js:820:12)
      at process._tickCallback (internal/process/next_tick.js:63:19)



  Error: component---src-pages-404-tsx-a8a926f03b8bdceea050.js from Terser
  TypeError: Cannot read property 'minify' of undefined
      at minify (/home/ubuntu/pet/podabed.org/node_modules/terser-webpack-plugin  /dist/minify.js:175:23)
      at module.exports (/home/ubuntu/pet/podabed.org/node_modules/terser-webpac  k-plugin/dist/worker.js:13:40)
      at handle (/home/ubuntu/pet/podabed.org/node_modules/worker-farm/lib/child  /index.js:44:8)
      at process.<anonymous> (/home/ubuntu/pet/podabed.org/node_modules/worker-f  arm/lib/child/index.js:51:3)
      at process.emit (events.js:189:13)
      at emit (internal/child_process.js:820:12)
      at process._tickCallback (internal/process/next_tick.js:63:19)



  Error: component---src-pages-about-tsx-92da9f3f2ee42b753bdd.js from Terser
  TypeError: Cannot read property 'minify' of undefined
      at minify (/home/ubuntu/pet/podabed.org/node_modules/terser-webpack-plugin  /dist/minify.js:175:23)
      at module.exports (/home/ubuntu/pet/podabed.org/node_modules/terser-webpac  k-plugin/dist/worker.js:13:40)
      at handle (/home/ubuntu/pet/podabed.org/node_modules/worker-farm/lib/child  /index.js:44:8)
      at process.<anonymous> (/home/ubuntu/pet/podabed.org/node_modules/worker-f  arm/lib/child/index.js:51:3)
      at process.emit (events.js:189:13)
      at emit (internal/child_process.js:820:12)
      at process._tickCallback (internal/process/next_tick.js:63:19)



  Error: component---src-pages-blog-tsx-db2a6de4c1c183b55120.js from Terser
  TypeError: Cannot read property 'minify' of undefined
      at minify (/home/ubuntu/pet/podabed.org/node_modules/terser-webpack-plugin  /dist/minify.js:175:23)
      at module.exports (/home/ubuntu/pet/podabed.org/node_modules/terser-webpac  k-plugin/dist/worker.js:13:40)
      at handle (/home/ubuntu/pet/podabed.org/node_modules/worker-farm/lib/child  /index.js:44:8)
      at process.<anonymous> (/home/ubuntu/pet/podabed.org/node_modules/worker-f  arm/lib/child/index.js:51:3)
      at process.emit (events.js:189:13)
      at emit (internal/child_process.js:820:12)
      at process._tickCallback (internal/process/next_tick.js:63:19)



  Error: component---src-pages-books-tsx-122cef08d0229fd13227.js from Terser
  TypeError: Cannot read property 'minify' of undefined
      at minify (/home/ubuntu/pet/podabed.org/node_modules/terser-webpack-plugin  /dist/minify.js:175:23)
      at module.exports (/home/ubuntu/pet/podabed.org/node_modules/terser-webpac  k-plugin/dist/worker.js:13:40)
      at handle (/home/ubuntu/pet/podabed.org/node_modules/worker-farm/lib/child  /index.js:44:8)
      at process.<anonymous> (/home/ubuntu/pet/podabed.org/node_modules/worker-f  arm/lib/child/index.js:51:3)
      at process.emit (events.js:189:13)
      at emit (internal/child_process.js:820:12)
      at process._tickCallback (internal/process/next_tick.js:63:19)



  Error: component---src-pages-index-tsx-53d17582f9ddd1d608d9.js from Terser
  TypeError: Cannot read property 'minify' of undefined
      at minify (/home/ubuntu/pet/podabed.org/node_modules/terser-webpack-plugin  /dist/minify.js:175:23)
      at module.exports (/home/ubuntu/pet/podabed.org/node_modules/terser-webpac  k-plugin/dist/worker.js:13:40)
      at handle (/home/ubuntu/pet/podabed.org/node_modules/worker-farm/lib/child  /index.js:44:8)
      at process.<anonymous> (/home/ubuntu/pet/podabed.org/node_modules/worker-f  arm/lib/child/index.js:51:3)
      at process.emit (events.js:189:13)
      at emit (internal/child_process.js:820:12)
      at process._tickCallback (internal/process/next_tick.js:63:19)



  Error: component---src-pages-inscriptions-tsx-a32f8aeb1451b65c35b9.js from Ter  ser
  TypeError: Cannot read property 'minify' of undefined
      at minify (/home/ubuntu/pet/podabed.org/node_modules/terser-webpack-plugin  /dist/minify.js:175:23)
      at module.exports (/home/ubuntu/pet/podabed.org/node_modules/terser-webpac  k-plugin/dist/worker.js:13:40)
      at handle (/home/ubuntu/pet/podabed.org/node_modules/worker-farm/lib/child  /index.js:44:8)
      at process.<anonymous> (/home/ubuntu/pet/podabed.org/node_modules/worker-f  arm/lib/child/index.js:51:3)
      at process.emit (events.js:189:13)
      at emit (internal/child_process.js:820:12)
      at process._tickCallback (internal/process/next_tick.js:63:19)



  Error: component---src-pages-video-tsx-516e158716eea7406f3c.js from Terser
  TypeError: Cannot read property 'minify' of undefined
      at minify (/home/ubuntu/pet/podabed.org/node_modules/terser-webpack-plugin  /dist/minify.js:175:23)
      at module.exports (/home/ubuntu/pet/podabed.org/node_modules/terser-webpac  k-plugin/dist/worker.js:13:40)
      at handle (/home/ubuntu/pet/podabed.org/node_modules/worker-farm/lib/child  /index.js:44:8)
      at process.<anonymous> (/home/ubuntu/pet/podabed.org/node_modules/worker-f  arm/lib/child/index.js:51:3)
      at process.emit (events.js:189:13)
      at emit (internal/child_process.js:820:12)
      at process._tickCallback (internal/process/next_tick.js:63:19)



  Error: component---src-pages-wishlist-tsx-f551164ed8439f493ebe.js from Terser
  TypeError: Cannot read property 'minify' of undefined
      at minify (/home/ubuntu/pet/podabed.org/node_modules/terser-webpack-plugin  /dist/minify.js:175:23)
      at module.exports (/home/ubuntu/pet/podabed.org/node_modules/terser-webpac  k-plugin/dist/worker.js:13:40)
      at handle (/home/ubuntu/pet/podabed.org/node_modules/worker-farm/lib/child  /index.js:44:8)
      at process.<anonymous> (/home/ubuntu/pet/podabed.org/node_modules/worker-f  arm/lib/child/index.js:51:3)
      at process.emit (events.js:189:13)
      at emit (internal/child_process.js:820:12)
      at process._tickCallback (internal/process/next_tick.js:63:19)



  Error: component---src-templates-post-tsx-55b144e1e1e4be5739e5.js from Terser
  TypeError: Cannot read property 'minify' of undefined
      at minify (/home/ubuntu/pet/podabed.org/node_modules/terser-webpack-plugin  /dist/minify.js:175:23)
      at module.exports (/home/ubuntu/pet/podabed.org/node_modules/terser-webpac  k-plugin/dist/worker.js:13:40)
      at handle (/home/ubuntu/pet/podabed.org/node_modules/worker-farm/lib/child  /index.js:44:8)
      at process.<anonymous> (/home/ubuntu/pet/podabed.org/node_modules/worker-f  arm/lib/child/index.js:51:3)
      at process.emit (events.js:189:13)
      at emit (internal/child_process.js:820:12)
      at process._tickCallback (internal/process/next_tick.js:63:19)



  Error: pages-manifest-9d4e09a33285956e2def.js from Terser
  TypeError: Cannot read property 'minify' of undefined
      at minify (/home/ubuntu/pet/podabed.org/node_modules/terser-webpack-plugin  /dist/minify.js:175:23)
      at module.exports (/home/ubuntu/pet/podabed.org/node_modules/terser-webpac  k-plugin/dist/worker.js:13:40)
      at handle (/home/ubuntu/pet/podabed.org/node_modules/worker-farm/lib/child  /index.js:44:8)
      at process.<anonymous> (/home/ubuntu/pet/podabed.org/node_modules/worker-f  arm/lib/child/index.js:51:3)
      at process.emit (events.js:189:13)
      at emit (internal/child_process.js:820:12)
      at process._tickCallback (internal/process/next_tick.js:63:19)



  Error: webpack-runtime-c06633d0419170ab8da4.js from Terser
  TypeError: Cannot read property 'minify' of undefined
      at minify (/home/ubuntu/pet/podabed.org/node_modules/terser-webpack-plugin  /dist/minify.js:175:23)
      at module.exports (/home/ubuntu/pet/podabed.org/node_modules/terser-webpac  k-plugin/dist/worker.js:13:40)
      at handle (/home/ubuntu/pet/podabed.org/node_modules/worker-farm/lib/child  /index.js:44:8)
      at process.<anonymous> (/home/ubuntu/pet/podabed.org/node_modules/worker-f  arm/lib/child/index.js:51:3)
      at process.emit (events.js:189:13)
      at emit (internal/child_process.js:820:12)
      at process._tickCallback (internal/process/next_tick.js:63:19)

error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Process finished with exit code 1
confirmed upstream

Most helpful comment

deammer's suggested workaround above did not help build succeed for me but pitops suggestion on terser-webpack-plugin did:

As a workaround for now if you use yarn you can add a resolution to a fixed terser version. Delete yarn.lock first and node_modules

Example (in your package.json)

"resolutions": {
  "terser": "3.14.1"
}

YMMV but thought I would drop it in here in case it helps someone else.

All 7 comments

I get the same errors with the latest packges - reverting to the versions I had before avoids this error.

Working setup
gatsby info --clipboard

  System:
    OS: macOS 10.14.2
    CPU: (8) x64 Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz
    Shell: 5.7 - /usr/local/bin/zsh
  Binaries:
    Node: 11.9.0 - /usr/local/bin/node
    Yarn: 1.13.0 - /usr/local/bin/yarn
    npm: 6.5.0 - /usr/local/bin/npm
  Languages:
    Python: 2.7.15 - /usr/local/bin/python
  Browsers:
    Chrome: 72.0.3626.81
    Firefox: 64.0.2
    Safari: 12.0.2
  npmPackages:
    gatsby: ^2.0.85 => 2.0.85
    gatsby-image: ^2.0.20 => 2.0.25
    gatsby-plugin-manifest: ^2.0.9 => 2.0.13
    gatsby-plugin-offline: ^2.0.16 => 2.0.21
    gatsby-plugin-react-helmet: ^3.0.2 => 3.0.5
    gatsby-plugin-sharp: ^2.0.14 => 2.0.17
    gatsby-plugin-styled-components: ^3.0.4 => 3.0.4
    gatsby-remark-autolink-headers: ^2.0.12 => 2.0.12
    gatsby-remark-images: ^3.0.1 => 3.0.1
    gatsby-remark-katex: ^3.0.1 => 3.0.1
    gatsby-remark-prismjs: ^3.2.0 => 3.2.0
    gatsby-remark-smartypants: ^2.0.7 => 2.0.7
    gatsby-source-filesystem: ^2.0.12 => 2.0.12
    gatsby-transformer-remark: ^2.1.19 => 2.1.19
    gatsby-transformer-sharp: ^2.1.8 => 2.1.10
    gatsby-transformer-yaml: ^2.1.6 => 2.1.6
  npmGlobalPackages:
    gatsby-cli: 2.4.8

Broken setup (npmPackages only, rest is the same as above)

  npmPackages:
    gatsby: ^2.0.85 => 2.0.111
    gatsby-image: ^2.0.20 => 2.0.29
    gatsby-plugin-manifest: ^2.0.9 => 2.0.17
    gatsby-plugin-offline: ^2.0.16 => 2.0.22
    gatsby-plugin-react-helmet: ^3.0.2 => 3.0.6
    gatsby-plugin-sharp: ^2.0.14 => 2.0.20
    gatsby-plugin-styled-components: ^3.0.4 => 3.0.5
    gatsby-remark-autolink-headers: ^2.0.12 => 2.0.13
    gatsby-remark-images: ^3.0.1 => 3.0.3
    gatsby-remark-katex: ^3.0.1 => 3.0.3
    gatsby-remark-prismjs: ^3.2.0 => 3.2.4
    gatsby-remark-smartypants: ^2.0.7 => 2.0.8
    gatsby-source-filesystem: ^2.0.12 => 2.0.20
    gatsby-transformer-remark: ^2.1.19 => 2.2.3
    gatsby-transformer-sharp: ^2.1.8 => 2.1.13
    gatsby-transformer-yaml: ^2.1.6 => 2.1.8

Looks like a problem with terser-webpack-plugin:
https://github.com/terser-js/terser/pull/254

Here's the simplest workaround at the moment:

# npm
npm i --save-exact --save [email protected]

# yarn
yarn add [email protected] --exact

yes terser broke webpack. should be tempoorary. related issues: https://github.com/terser-js/terser/issues/251

The project generated by scaffold reported.

deammer's suggested workaround above did not help build succeed for me but pitops suggestion on terser-webpack-plugin did:

As a workaround for now if you use yarn you can add a resolution to a fixed terser version. Delete yarn.lock first and node_modules

Example (in your package.json)

"resolutions": {
  "terser": "3.14.1"
}

YMMV but thought I would drop it in here in case it helps someone else.

This was fixed in https://github.com/terser-js/terser/commit/03b08760fcac9ee3f633d7c8e82af417c47db4e7

Updating terser to v3.16.1 should fix this, closing this for now

Updating our terser-webpack-plugin dependency to always be higher than 1.2.2 so no one sees this anymore

terser is on 5.5.0 still broken

Was this page helpful?
0 / 5 - 0 ratings

Related issues

KyleAMathews picture KyleAMathews  ยท  3Comments

theduke picture theduke  ยท  3Comments

rossPatton picture rossPatton  ยท  3Comments

ghost picture ghost  ยท  3Comments

andykais picture andykais  ยท  3Comments