Skip to content

@wordpress/react-i18n is missing a dependency on react #55171

@anomiex

Description

@anomiex

After #54494, @wordpress/react-i18n is now lacking dependencies or peer dependencies on react. (other affected packages have since been fixed)

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/react-i18n jsdom global-jsdom
  5. 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/react-i18n global-jsdom (note pnpm 8 defaults to installing peer deps)
  4. 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/react-i18n tried to access react, but it isn't declared in its dependencies; this makes the require call ambiguous and unsound.

Required package: react (via "react/jsx-runtime")
Required by: @wordpress/react-i18n@npm:4.36.0 (via /home/user/.yarn/berry/cache/@wordpress-react-i18n-npm-4.36.0-164c2bcf50-10c0.zip/node_modules/@wordpress/react-i18n/build/)

Require stack:
- /home/user/.yarn/berry/cache/@wordpress-react-i18n-npm-4.36.0-164c2bcf50-10c0.zip/node_modules/@wordpress/react-i18n/build/index.js
- /tmp/test/[eval]
    at require$$0.Module._resolveFilename (/tmp/test/.pnp.cjs:6997: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:6883: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> (/home/user/.yarn/berry/cache/@wordpress-react-i18n-npm-4.36.0-164c2bcf50-10c0.zip/node_modules/@wordpress/react-i18n/build/index.js:30:26)

With pnpm:

Error: Cannot find module 'react/jsx-runtime'
Require stack:
- /tmp/test/node_modules/.pnpm/@[email protected]/node_modules/@wordpress/react-i18n/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]/node_modules/@wordpress/react-i18n/build/index.js:30:26)
    at Module._compile (node:internal/modules/cjs/loader:1706:14) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/tmp/test/node_modules/.pnpm/@[email protected]/node_modules/@wordpress/react-i18n/build/index.js',
    '/tmp/test/[eval]'
  ]
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    [Type] BugAn existing feature does not function as intended

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions