Skip to content

@wordpress/upload-media is missing a dependency or peer dependency on @babel/runtime and react #68694

@anomiex

Description

@anomiex

The package @wordpress/upload-media attempts to use @babel/runtime from ./build/index.js, build/store/index.js, and ./build/components/provider/index.js, but does not declare a dependency or peer dependency on that package.

It also attempts to use react from ./build-module/components/provider/index.js, ./build/components/provider/index.js, and a few other files, but does not declare a dependency or peer dependency on that package either.

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 yarn:

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

With pnpm:

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

Expected behavior

Output along the lines of

object

Actual behavior

With yarn:

Error: @wordpress/upload-media tried to access @babel/runtime, but it isn't declared in its dependencies; this makes the require call ambiguous and unsound.

Required package: @babel/runtime (via "@babel/runtime/helpers/interopRequireDefault")
Required by: @wordpress/upload-media@npm:0.1.0 (via /home/brad/.yarn/berry/cache/@wordpress-upload-media-npm-0.1.0-b86497bcf7-10c0.zip/node_modules/@wordpress/upload-media/build/)

Require stack:
- /home/brad/.yarn/berry/cache/@wordpress-upload-media-npm-0.1.0-b86497bcf7-10c0.zip/node_modules/@wordpress/upload-media/build/index.js
- /tmp/test/[eval]

With pnpm:

Error: Cannot find module '@babel/runtime/helpers/interopRequireDefault'
Require stack:
- /tmp/test/node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected]_react-dom@18._5ilcwks4ynxyxsosgzuhvejga4/node_modules/@wordpress/upload-media/build/index.js
- /tmp/test/[eval]

Metadata

Metadata

Assignees

Labels

[Feature] MediaAnything that impacts the experience of managing media[Status] In ProgressTracking issues with work in progress[Type] BugAn existing feature does not function as intended

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions