gatsby: MaxListenersExceededWarning errors with gatsby-plugin-image StaticImage with placeholder

Preliminary Checks

Description

A console error occurs on develop and build when using StaticImage from gatsby-plugin-image with a placeholder attribute, e.g:

<StaticImage src="../images/photo-1.jpg" alt="" placeholder="blurred" />

  • Using gatsby develop or gatsby build:
ERROR

(node:15194) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 end listeners added to [PassThrough]. Use emitter.setMaxListeners() to increase limit
(Use `node --trace-warnings ...` to show where the warning was created)
  • Using node --trace-warnings node_modules/.bin/gatsby develop:
ERROR 

(node:15473) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 end listeners added to [PassThrough]. Use emitter.setMaxListeners() to increase limit
    at _addListener (node:events:595:17)
    at PassThrough.addListener (node:events:617:10)
    at PassThrough.Readable.on (node:internal/streams/readable:899:35)
    at eos (node:internal/streams/end-of-stream:169:10)
    at pipe (node:internal/streams/pipeline:348:3)
    at pipelineImpl (node:internal/streams/pipeline:293:9)
    at pipeline (node:internal/streams/pipeline:146:10)
    at probeStream (/Users/hewitt/path/to/project/node_modules/probe-image-size/stream.js:63:8)
    at get_image_size (/Users/hewitt/path/to/project/node_modules/probe-image-size/index.js:13:12)
    at getImageSizeAsync (/Users/hewitt/path/to/project/node_modules/gatsby-plugin-sharp/index.js:63:28)
    at getImageMetadata (/Users/hewitt/path/to/project/node_modules/gatsby-plugin-sharp/image-data.js:33:39)
    at generateImageData (/Users/hewitt/path/to/project/node_modules/gatsby-plugin-sharp/image-data.js:123:26)
    at /Users/hewitt/path/to/project/node_modules/gatsby-plugin-image/dist/node-apis/image-processing.js:255:42
    at step (/Users/hewitt/path/to/project/node_modules/gatsby-plugin-image/dist/node-apis/image-processing.js:33:23)
    at Object.next (/Users/hewitt/path/to/project/node_modules/gatsby-plugin-image/dist/node-apis/image-processing.js:14:53)
    at /Users/hewitt/path/to/project/node_modules/gatsby-plugin-image/dist/node-apis/image-processing.js:8:71

Nothing seems to be visibly affected by the error - the build continues successfully afterwards.

Reproduction Link

https://github.com/jonohewitt/gatsby-image-bug-repro

Steps to Reproduce

  1. Install the reproduction project
  2. Run gatsby develop to see basic error
  3. Run node --trace-warnings node_modules/.bin/gatsby develop to see verbose error

Expected Result

No error

Actual Result

Error

Environment

System:
    OS: macOS 12.1
    CPU: (12) x64 Intel(R) Core(TM) i7-8700B CPU @ 3.20GHz
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 17.4.0 - /usr/local/bin/node
    Yarn: 1.22.17 - ~/.yarn/bin/yarn
    npm: 8.3.1 - /usr/local/bin/npm
  Languages:
    Python: 2.7.18 - /usr/bin/python
  Browsers:
    Chrome: 98.0.4758.80
    Safari: 15.2
  npmPackages:
    gatsby: ^4.7.1 => 4.7.1 
    gatsby-plugin-image: ^2.7.0 => 2.7.0 
    gatsby-plugin-sharp: ^4.7.0 => 4.7.0 
    gatsby-source-filesystem: ^4.7.0 => 4.7.0

Config Flags

No response

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 3
  • Comments: 15 (7 by maintainers)

Most upvoted comments

so probe-image-size in gatsby-plugin-sharp and gatsby-transformer-sharp should be updated to the latest version.

When this will happen, who knows 😛 they’re currently locked to v6!

That said, following this mindset and forcing an override by adding

"resolutions": {
  "probe-image-size": "^7.0.0"
},

Fixed the issue for me completely 👍. probe-image-size doesn’t seem to follow semver so 6 -> 7 didn’t appear to have any breaking changes based on their Changelog. Thanks @hendra-go!

Hello @danielmacuare

"resolutions": {
  "gatsby-plugin-sharp/probe-image-size": "^7.0.0"
}

The code above should be inserted to your project’s package.json it is a Yarn’s Selective dependency resolutions so you should use Yarn instead npm

As an example, i use this package.json from @jonohewitt’s repo

{
  "name": "gatsby-starter-minimal",
  "version": "1.0.0",
  "private": true,
  "description": "A Gatsby starter with no plugins and a single welcome page.",
  "author": "Laurie Barth",
  "keywords": [
    "gatsby"
  ],
  "scripts": {
    "develop": "gatsby develop",
    "start": "gatsby develop",
    "build": "gatsby build",
    "serve": "gatsby serve",
    "clean": "gatsby clean"
  },
  "license": "0BSD",
  "dependencies": {
    "gatsby": "^4.7.1",
    "gatsby-plugin-image": "^2.7.0",
    "gatsby-plugin-sharp": "^4.7.0",
    "gatsby-source-filesystem": "^4.7.0",
    "react": "^17.0.1",
    "react-dom": "^17.0.1"
  },
  "resolutions": {
    "gatsby-plugin-sharp/probe-image-size": "^7.0.0"
  }
}

After you insert the resolutions, run yarn install again

$ node --trace-warnings node_modules/.bin/gatsby develop
E:\web-development\github\projectname-gatsby\node_modules\.bin\gatsby:2
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
          ^^^^^^^

SyntaxError: missing ) after argument list
←[90m    at Object.compileFunction (node:vm:352:18)←[39m
←[90m    at wrapSafe (node:internal/modules/cjs/loader:1026:15)←[39m
←[90m    at Module._compile (node:internal/modules/cjs/loader:1061:27)←[39m
←[90m    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1151:10)←[39m
←[90m    at Module.load (node:internal/modules/cjs/loader:975:32)←[39m
←[90m    at Function.Module._load (node:internal/modules/cjs/loader:822:12)←[39m
←[90m    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)←[39m
←[90m    at node:internal/main/run_main_module:17:47←[39m

Node.js v17.5.0

This is what I’m getting.

I can confirm that I am seing the exact same issue here, however the placeholder attribute is being set in the graphql query in my case.

However I am running node 14.xx and Gatsby 3.x with Gatsby image plugin 1.13.0.