Skip to content

fix: webpack + React 17 won't build because of named imports of React 18 APIs - #8938

Merged
ryanflorence merged 2 commits into
remix-run:devfrom
haivuw:dev
Jun 7, 2022
Merged

ryanflorence merged 2 commits into
remix-run:devfrom
haivuw:dev

Conversation

@haivuw

@haivuw haivuw commented Jun 6, 2022 •

Copy link
Copy Markdown
Contributor

Fixes #8931 (Reopen since /remixing is deleted)
In current build, rollup outputs these named exports: useSyncExternalStore, startTransition from React. If the user's React version doesn't export them, Webpack won't build:

ERROR in ./node_modules/react-router/index.js 61:10-25
export 'startTransition' (imported as 'startTransition') was not found in 'react'

This fix prevents rollup from outputting these named imports.
node_modules/react-router/index.js:

//before
import { startTransition, useSyncExternalStore as useSyncExternalStore$3, createContext, useContext, useMemo, useRef, useEffect as useEffect$1, useCallback, createElement, Fragment, Component, useState as useState$1, useLayoutEffect as useLayoutEffect$1, Children, isValidElement } from 'react';

//after
import { createContext, useContext, useMemo, useRef, useEffect as useEffect$1, useCallback, createElement, Fragment, Component, useState as useState$1, useLayoutEffect as useLayoutEffect$1, Children, isValidElement } from 'react';

https://rollupjs.org/guide/en/#outputinterop
https://github.dev/webpack/webpack/blob/f9e6b682aba059d13aa3e170ac42b7a797a0ef3f/lib/dependencies/HarmonyImportDependency.js#L141

@brophdawg11

Copy link
Copy Markdown
Contributor

Interesting - thanks for the PR! We'd ideally use the use-sync-external-store shim directly but it causes some module build issues for us at the moment so we had to pull it in. react/react#24590

@ryanflorence
ryanflorence merged commit 3bb0a91 into remix-run:dev Jun 7, 2022
brophdawg11 added a commit that referenced this pull request Mar 27, 2024
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Matt Brophy <matt@brophy.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants