expo: [SDK46][Web] ReactDOM.render is no longer supported in React 18
Summary
When I upgrade an existing projet to SDK 46 (React 18) or when I create a new blank project, and running on web I have this error: ‘Warning: ReactDOM.render is no longer supported in React 18. Use createRoot instead. Until you switch to the new API, your app will behave as if it’s running React 17. Learn more: https://reactjs.org/link/switch-to-createroot’
Managed or bare workflow? If you have ios/
or android/
directories in your project, the answer is bare!
managed
What platform(s) does this occur on?
Web
SDK Version (managed workflow only)
46
Environment
expo-env-info 1.0.5 environment info: System: OS: macOS 11.6 Shell: 5.8 - /bin/zsh Binaries: Node: 16.14.0 - ~/.nvm/versions/node/v16.14.0/bin/node Yarn: 1.22.19 - ~/.nvm/versions/node/v16.14.0/bin/yarn npm: 8.3.1 - ~/.nvm/versions/node/v16.14.0/bin/npm Watchman: 2022.03.21.00 - /usr/local/bin/watchman Managers: CocoaPods: 1.11.3 - /usr/local/bin/pod SDKs: iOS SDK: Platforms: DriverKit 21.2, iOS 15.2, macOS 12.1, tvOS 15.2, watchOS 8.3 IDEs: Android Studio: 4.2 AI-202.7660.26.42.7486908 Xcode: 13.2.1/13C100 - /usr/bin/xcodebuild npmPackages: @expo/webpack-config: ^0.17.0 => 0.17.0 expo: ~46.0.2 => 46.0.2 react: 18.0.0 => 18.0.0 react-dom: 18.0.0 => 18.0.0 react-native: 0.69.3 => 0.69.3 react-native-web: ~0.18.7 => 0.18.7 Expo Workflow: managed
Reproducible demo
Juste clone the default tabs or blank template and run on web.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 34
- Comments: 24 (6 by maintainers)
Commits related to this issue
- ✨ feat: use custom entry To use react18 with expo in web platform, we need to custom the entry file instead of use default expo entry. [see this](https://github.com/expo/expo/issues/18485) — committed to tohsaka888/react-native-table by tohsaka888 2 years ago
- ✨ feat: custom entry To use react18 with expo in web platform, we need to custom the entry file instead of use default expo entry. [see this](https://github.com/expo/expo/issues/18485) — committed to tohsaka888/react-native-table by tohsaka888 2 years ago
- Use React 18 mounting pattern on web to avoid web warning (#20965) # Why - fix #18485 <!-- Please describe the motivation for this PR, and link to relevant GitHub issues, forums posts, or fea... — committed to expo/expo by EvanBacon a year ago
Giving credit to all those above who started me on this solution, i did this:
"node_modules/expo/AppEntry.js"
to a custom file:"main": "entry.js"
entry.js
I haven’t tested it too too much but what i’ve tested thus far has worked. I’m doing an ios/android/web build and all 3 seem to be working on SDK 47. Hope this helps!
Basically identical to @JamesHemery’s solution, here’s what I did for my web-only app (may or may not work fine for non-web apps):
Change “main” in package.json from
"node_modules/expo/AppEntry.js"
to a custom file:"main": "entry.js"
Created
entry.js
Temporary fixed by creating a custom index file or by patching registerRootComponent function (following React doc), but IDK if it’s the good way for an Expo patch :
Update for SDK 47 :
same issue +1 Look forward to the official solution for the warning.
Issue probably needs to be addressed upstream in react-native-web https://github.com/necolas/react-native-web/blob/3fc40bdf810901146b8a240a2d0399dee708cfff/packages/react-native-web/src/exports/render/index.js#L10
The workaround from above no longer works in SDK 47 because
withExpoRoot
no longer exists.Also related to this PR to fully embrace the concurrent React
https://github.com/necolas/react-native-web/pull/2330
==============
Update 9/Nov/2022
And it seems like the above PR is deprecated according to the latest comment.
I am really sorry to at you( @necolas ), I just want to know if I am tracking the correct PR, is this https://github.com/necolas/react-native-web/pull/2330 the key to addressing this issue? or i should look at something else? 😃 Thanks in advance.
This is not an error, it’s a warning. The API still works. React Native and React Native for Web do not officially support the new APIs in React 18 yet
same issue here, thanks for help, I’ll wait for the solution here, thanks
@JamesHemery Hehe. I am bootstrapping a new project - and 30m after you posted this, I was thinking about doing the same thing. ^ But I realized the amount of foreign code/imports I would have to fork into my app and decided I would live with the annoying error until it gets fixed upstream. Thank you for the diligence in reporting!
@JamesHemery Thanks
Thank you James. This worked for me.
same issue +1
+1