Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@wordpress/icons, @wordpress/interactivity, and @wordpress/react-i18n are missing a dependency on react #55171

Open
anomiex opened this issue Oct 9, 2023 · 0 comments · May be fixed by #55178
Assignees
Labels
[Status] In Progress Tracking issues with work in progress [Type] Bug An existing feature does not function as intended

Comments

@anomiex
Copy link
Contributor

anomiex commented Oct 9, 2023

After #54494, @wordpress/icons, @wordpress/interactivity, and @wordpress/react-i18n are now lacking dependencies or peer dependencies on react.

@wordpress/interactivity also appears to be lacking a dependency or peer dependency on @babel/runtime.

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/icons @wordpress/interactivity @wordpress/react-i18n jsdom global-jsdom @babel/runtime
  5. Run one of these:
    • yarn node -e 'require( "global-jsdom/register" ); const x = require( "@wordpress/icons" ); console.log( typeof x );'
    • yarn node -e 'require( "global-jsdom/register" ); const x = require( "@wordpress/interactivity" ); console.log( typeof x );'
    • yarn node -e 'require( "global-jsdom/register" ); const x = require( "@wordpress/react-i18n" ); console.log( typeof x );'

With pnpm:

  1. Create a temporary directory, and cd into it.
  2. echo 'hoist-pattern=[]' > .npmrc
  3. pnpm add @wordpress/icons @wordpress/interactivity @wordpress/react-i18n global-jsdom @babel/runtime (note pnpm 8 defaults to installing peer deps)
  4. Run one of these:
    • node -e 'require( "global-jsdom/register" ); const x = require( "@wordpress/icons" ); console.log( typeof x );'
    • node -e 'require( "global-jsdom/register" ); const x = require( "@wordpress/interactivity" ); console.log( typeof x );'
    • node -e 'require( "global-jsdom/register" ); const x = require( "@wordpress/react-i18n" ); console.log( typeof x );'

Expected behavior

Output along the lines of

object

Actual behavior

With yarn:

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

Required package: react
Required by: @wordpress/icons@npm:9.34.0 (via /tmp/test/.yarn/cache/@wordpress-icons-npm-9.34.0-4ebc5746be-e1b3bf3619.zip/node_modules/@wordpress/icons/build/library/)

Require stack:
- /tmp/test/.yarn/cache/@wordpress-icons-npm-9.34.0-4ebc5746be-e1b3bf3619.zip/node_modules/@wordpress/icons/build/library/add-card.js
- /tmp/test/.yarn/cache/@wordpress-icons-npm-9.34.0-4ebc5746be-e1b3bf3619.zip/node_modules/@wordpress/icons/build/index.js

With pnpm:

Error: Cannot find module 'react'
Require stack:
- /tmp/test/node_modules/.pnpm/@wordpress+icons@9.34.0/node_modules/@wordpress/icons/build/library/add-card.js
- /tmp/test/node_modules/.pnpm/@wordpress+icons@9.34.0/node_modules/@wordpress/icons/build/index.js
anomiex added a commit to anomiex/gutenberg that referenced this issue Oct 9, 2023
Build code transformations can introduce dependencies on packages such
as `react` and `@babel/runtime`. These need to be declared if the
package is to function correctly with yarn's p'n'p or pnpm with hoisting
disabled.

After WordPress#54494, `@wordpress/icons`, `@wordpress/interactivity`, and
`@wordpress/react-i18n` are now lacking peer dependencies on react.

`@wordpress/interactivity` also appears to be lacking a dependency or
peer dependency on `@babel/runtime`.

Fixes WordPress#55171
@anomiex anomiex linked a pull request Oct 9, 2023 that will close this issue
@github-actions github-actions bot added the [Status] In Progress Tracking issues with work in progress label Oct 9, 2023
@jordesign jordesign added [Type] Bug An existing feature does not function as intended [Package] Components /packages/components labels Oct 9, 2023
@mirka mirka removed the [Package] Components /packages/components label Dec 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Status] In Progress Tracking issues with work in progress [Type] Bug An existing feature does not function as intended
3 participants