Skip to content

@wordpress/image-cropper missing dependency or peer dependency on react #74394

@anomiex

Description

@anomiex

@wordpress/image-cropper is missing a dependency or peer dependency on react.

This happens to work with npm's hoisting due to other dependencies pulling that package in, but will fail with yarn's p'n'p or pnpm with hoisting disabled.

Reproduction

With pnpm:

  1. Create a temporary directory, and cd into it.
  2. echo 'hoist-pattern=[]' > .npmrc
  3. pnpm add @wordpress/image-cropper
  4. node -e 'const x = require( "@wordpress/image-cropper" ); console.log( typeof x );'

With yarn:

  1. Create a temporary directory, and cd into it.
  2. echo '{}' > package.json
  3. yarn set version stable
  4. yarn add @wordpress/image-cropper
  5. yarn node -e 'const x = require( "@wordpress/image-cropper" ); console.log( typeof x );'

Expected behavior

Output along the lines of

object

Actual behavior

With pnpm:

Error: Cannot find module 'react/jsx-runtime'
Require stack:
- /tmp/test/node_modules/.pnpm/@[email protected][email protected][email protected][email protected]/node_modules/@wordpress/image-cropper/build/provider/index.js
- /tmp/test/node_modules/.pnpm/@[email protected][email protected][email protected][email protected]/node_modules/@wordpress/image-cropper/build/components/image-cropper/index.js
- /tmp/test/node_modules/.pnpm/@[email protected][email protected][email protected][email protected]/node_modules/@wordpress/image-cropper/build/index.js
- /tmp/test/[eval]
    at Function._resolveFilename (node:internal/modules/cjs/loader:1383:15)
    at defaultResolveImpl (node:internal/modules/cjs/loader:1025:19)
    at resolveForCJSWithHooks (node:internal/modules/cjs/loader:1030:22)
    at Function._load (node:internal/modules/cjs/loader:1192:37)
    at TracingChannel.traceSync (node:diagnostics_channel:328:14)
    at wrapModuleLoad (node:internal/modules/cjs/loader:237:24)
    at Module.require (node:internal/modules/cjs/loader:1463:12)
    at require (node:internal/modules/helpers:147:16)
    at Object.<anonymous> (/tmp/test/node_modules/.pnpm/@[email protected][email protected][email protected][email protected]/node_modules/@wordpress/image-cropper/build/provider/index.js:41:26)
    at Module._compile (node:internal/modules/cjs/loader:1706:14) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/tmp/test/node_modules/.pnpm/@[email protected][email protected][email protected][email protected]/node_modules/@wordpress/image-cropper/build/provider/index.js',
    '/tmp/test/node_modules/.pnpm/@[email protected][email protected][email protected][email protected]/node_modules/@wordpress/image-cropper/build/components/image-cropper/index.js',
    '/tmp/test/node_modules/.pnpm/@[email protected][email protected][email protected][email protected]/node_modules/@wordpress/image-cropper/build/index.js',
    '/tmp/test/[eval]'
  ]
}

With yarn:

Error: react-easy-crop tried to access react (a peer dependency) but it isn't provided by its ancestors; this makes the require call ambiguous and unsound.

Required package: react
Required by: react-easy-crop@virtual:3f52e675167bee425db139dfbca5db0da473291ee5ca10915f036f9f2e3dd2a594866c8f2219b8fd710c5b6d6c65a56f4a4d9b2a1f3b8b481d1660bd2b7cc179#npm:5.5.6 (via /tmp/test/.yarn/__virtual__/react-easy-crop-virtual-60cc6f0452/3/home/user/.yarn/berry/cache/react-easy-crop-npm-5.5.6-18a4454b18-10c0.zip/node_modules/react-easy-crop/)

Ancestor breaking the chain: @wordpress/image-cropper@npm:1.1.0


Require stack:
- /tmp/test/.yarn/__virtual__/react-easy-crop-virtual-60cc6f0452/3/home/user/.yarn/berry/cache/react-easy-crop-npm-5.5.6-18a4454b18-10c0.zip/node_modules/react-easy-crop/index.js
- /home/user/.yarn/berry/cache/@wordpress-image-cropper-npm-1.1.0-3f52e67516-10c0.zip/node_modules/@wordpress/image-cropper/build/components/image-cropper/index.js
- /home/user/.yarn/berry/cache/@wordpress-image-cropper-npm-1.1.0-3f52e67516-10c0.zip/node_modules/@wordpress/image-cropper/build/index.js
- /tmp/test/[eval]
    at require$$0.Module._resolveFilename (/tmp/test/.pnp.cjs:6338:13)
    at defaultResolveImpl (node:internal/modules/cjs/loader:1025:19)
    at resolveForCJSWithHooks (node:internal/modules/cjs/loader:1030:22)
    at Function.<anonymous> (node:internal/modules/cjs/loader:1192:37)
    at require$$0.Module._load (/tmp/test/.pnp.cjs:6224:31)
    at TracingChannel.traceSync (node:diagnostics_channel:328:14)
    at wrapModuleLoad (node:internal/modules/cjs/loader:237:24)
    at Module.require (node:internal/modules/cjs/loader:1463:12)
    at require (node:internal/modules/helpers:147:16)
    at Object.<anonymous> (/tmp/test/.yarn/__virtual__/react-easy-crop-virtual-60cc6f0452/3/home/user/.yarn/berry/cache/react-easy-crop-npm-5.5.6-18a4454b18-10c0.zip/node_modules/react-easy-crop/index.js:6:13)

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions