Skip to content

Regression: @primer/react is depends on esm only module @github/combobox-nav #2245

@okuryu

Description

@okuryu

Describe the bug
This is a similar problem to #2238. When I try to use the latest @primer/react in the Next.js app, I get the following error:

> next build

info  - SWC minify release candidate enabled. https://nextjs.link/swcmin
info  - Linting and checking validity of types
info  - Creating an optimized production build
info  - Compiled successfully
info  - Collecting page data ...Error [ERR_REQUIRE_ESM]: require() of ES Module /Users/rokumura/work/tests/test-20220819/my-app/node_modules/@github/combobox-nav/dist/index.js from /Users/rokumura/work/tests/test-20220819/my-app/node_modules/@primer/react/lib/drafts/hooks/useCombobox.js not supported.
Instead change the require of index.js in /Users/rokumura/work/tests/test-20220819/my-app/node_modules/@primer/react/lib/drafts/hooks/useCombobox.js to a dynamic import() which is available in all CommonJS modules.
    at Object.<anonymous> (/Users/rokumura/work/tests/test-20220819/my-app/node_modules/@primer/react/lib/drafts/hooks/useCombobox.js:8:43)
    at Object.<anonymous> (/Users/rokumura/work/tests/test-20220819/my-app/node_modules/@primer/react/lib/drafts/InlineAutocomplete/_AutocompleteSuggestions.js:16:20)
    at Object.<anonymous> (/Users/rokumura/work/tests/test-20220819/my-app/node_modules/@primer/react/lib/drafts/InlineAutocomplete/InlineAutocomplete.js:22:55)
    at Object.<anonymous> (/Users/rokumura/work/tests/test-20220819/my-app/node_modules/@primer/react/lib/drafts/InlineAutocomplete/index.js:8:50)
    at Object.<anonymous> (/Users/rokumura/work/tests/test-20220819/my-app/node_modules/@primer/react/lib/FormControl/FormControl.js:28:50)
    at Object.<anonymous> (/Users/rokumura/work/tests/test-20220819/my-app/node_modules/@primer/react/lib/FormControl/index.js:13:43)
    at Object.<anonymous> (/Users/rokumura/work/tests/test-20220819/my-app/node_modules/@primer/react/lib/index.js:669:43)
    at Object.551 (/Users/rokumura/work/tests/test-20220819/my-app/.next/server/pages/_app.js:22:31)
    at __webpack_require__ (/Users/rokumura/work/tests/test-20220819/my-app/.next/server/webpack-runtime.js:25:42)
    at __webpack_exec__ (/Users/rokumura/work/tests/test-20220819/my-app/.next/server/pages/_app.js:51:39)
    at /Users/rokumura/work/tests/test-20220819/my-app/.next/server/pages/_app.js:52:28
    at Object.<anonymous> (/Users/rokumura/work/tests/test-20220819/my-app/.next/server/pages/_app.js:55:3)
    at Object.requirePage (/Users/rokumura/work/tests/test-20220819/my-app/node_modules/next/dist/server/require.js:58:12)
    at /Users/rokumura/work/tests/test-20220819/my-app/node_modules/next/dist/server/load-components.js:55:50
    at async Promise.all (index 1)
    at async Object.loadComponents (/Users/rokumura/work/tests/test-20220819/my-app/node_modules/next/dist/server/load-components.js:53:49)
    at async /Users/rokumura/work/tests/test-20220819/my-app/node_modules/next/dist/build/utils.js:673:21
    at async Span.traceAsyncFn (/Users/rokumura/work/tests/test-20220819/my-app/node_modules/next/dist/trace/trace.js:79:20) {
  code: 'ERR_REQUIRE_ESM'
}

> Build error occurred
Error: Failed to collect page data for /
    at /Users/rokumura/work/tests/test-20220819/my-app/node_modules/next/dist/build/utils.js:743:15
    at processTicksAndRejections (node:internal/process/task_queues:96:5) {
  type: 'Error'
}

I am guessing that @github/combobox-nav is the ESM only module.

To Reproduce
Steps to reproduce the behavior:

  1. Create Next.js + TypeScript app via create-next-app

  2. Edit package.json as follows:

    {
      "name": "my-app",
      "version": "0.1.0",
      "private": true,
      "scripts": {
        "dev": "next dev",
        "build": "next build",
        "start": "next start",
        "lint": "next lint"
      },
      "dependencies": {
        "@primer/react": "35.7.0",
        "next": "12.2.5",
        "react": "17.0.2",
        "react-dom": "17.0.2"
      },
      "devDependencies": {
        "@types/node": "18.7.6",
        "@types/react": "17.0.48",
        "@types/react-dom": "17.0.17",
        "eslint": "8.22.0",
        "eslint-config-next": "12.2.5",
        "typescript": "4.7.4"
      }
    }
  3. Edit pages/_app.tsx as follows:

    import type { AppProps } from 'next/app'
    import { SSRProvider } from '@primer/react'
    
    function MyApp({ Component, pageProps }: AppProps) {
      return (
        <SSRProvider>
          <title>Test</title>
        </SSRProvider>
      )
    }
    
    export default MyApp
  4. Run npm run build command

Expected behavior
This error does not occur when using @primer/[email protected], so I expect the latest version work as well.

Screenshots
N/A

Desktop (please complete the following information):
N/A

Smartphone (please complete the following information):
N/A

Additional context
N/A

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions