-
Notifications
You must be signed in to change notification settings - Fork 476
Support NextJS 11 #3579
Description
Original issue
@expo/next-adapter only supports NextJS 9.x. which is now two major versions behind. The Next adapter is broken for two reasons
- Compile error 'Missing class properties transform' when using Next >=10.0.2 Compile error 'Missing class properties transform' when using Next >=10.0.2 #3226
- Please upgrade @expo/webpack-config's webpack dependency to 5.x Please upgrade @expo/webpack-config's webpack dependency to 5.x #2881
I'm creating this issue to discuss just updating just @expo/next-adapter (not Expo web) to the latest NextJS version with webpack 5 support.
Here is a working proof of concept https://github.com/marklawlor/expo-nextjs-webpack-5.
@EvanBacon Whats the best way to PR these patches without breaking Expo web?
In #2881 you indicated that you wished to wait for Create React App to update, but @expo/next-adapter only uses the withUnimodules addon which requires minimal changes which could be added in a non-breaking manner behind flags.
PRs
- [babel-preset-expo] Improve detection for NextJS 11 as a bundler expo#13327
- [feat] Update next-adapter for NextJS 11.x #3586
Known issues / workarounds
My app doesn't compile when enabling webpack5
Note: If your app doesn't not compile under webpack 4 then you have a different issue
The Expo's babel loader automatically transpiles some dependencies, however there seems to be some edge cases where it doesn't work under webpack5.
The workaround is to explicitly list these modules via next-transpile-modules. See this comment for more info #3579 (comment)
My app doesn't compile under webpack 4 or 5, but previously worked
Check your console output, you probably have an error complaining about es6 syntax, maybe a message like SyntaxError: ./node_modules/<modules>/<path>.js: Missing class properties transform.
NextJS have updated their compile targets and removed some babel transforms that were previously needed for react-native modules. You will need to add these as babel overrides in your babel.config.js #3579 (comment)
My monorepo doesn't compile
See this comment #3579 (comment)
My expo app has a JSX transform error
NextJS 11 w/ React 17 uses the new JSX transform. You should enable useTransformReactJsxExperimental for all platforms.
"React.createElement is not a function"
The JSX transform does not require you to import React, so it may have been removed from a shared component. Consider switching to useTransformReactJsxExperimental for all platforms.
I'm getting Postcss errors from NextJS
Run npm list postcss. NextJS has a peerDependancy on PostCSS 8 and you may have to install this peerDependancy yourself.