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

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

Merged
merged 2 commits into from
Jun 7, 2022

Conversation

haivuw
Copy link
Contributor

@haivuw haivuw commented Jun 6, 2022

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
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. facebook/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.

None yet

3 participants