Support for react-native-web _worked in Next.js 4_, but now throws an error when upgrading to Next.js 5. From my research, this would appear to be related to an issue that has been closed in necolas/react-native-web#364.
The Next.js server should successfully compile and load the application without errors.
The Next.js server throws an error and failed to compile.
ERROR Failed to compile with 1 errors
This dependency was not found:
* react-dom/unstable-native-dependencies in ./node_modules/react-native-web/dist/modules/injectResponderEventPlugin/index.js
To install it, you can run: npm install --save react-dom/unstable-native-dependencies
yarn add react-native-webyarn add -D babel-plugin-react-native-web.babelrc configured for the plugin installed in previous stepreact-native-web (see slightly different example below to match latest version of react-native-web)yarn startThe Next.js application is unable to compile.
| Tech | Version |
|---------|---------|
| next | 5.0.0 |
| node | 8.9.4 |
| OS | macOS 10.13.3 |
| browser | Chrome 64.0.3282.140 |
| react-native-web | 0.4.0 |
import Document, { Head, Main, NextScript } from 'next/document';
import React from 'react';
import { AppRegistry } from 'react-native-web';
import { renderToStaticMarkup } from 'react-dom/server';
export default class MyDocument extends Document {
static async getInitialProps({ renderPage }) {
AppRegistry.registerComponent('Main', () => Main);
const { getStyleElement } = AppRegistry.getApplication('Main');
const page = renderPage();
const styles = [getStyleElement()];
return { ...page, styles };
}
render() {
return (
<html style={{ height: '100%', width: '100%' }}>
<Head />
<body style={{ height: '100%', width: '100%', overflowY: 'scroll' }}>
<Main />
<NextScript />
</body>
</html>
);
}
}
@dcalhoun we fixed a related issue for this.
Could you try this version: https://github.com/zeit/next.js/releases/tag/5.0.1-canary.2
@arunoda for posterity, the fix within [email protected] does resolve this issue. Thank you!
This fixes issues with react-dom/server also.
I was using react-quill and 5.0.0 broke the whole thing. using canary.2 fixes that.
Thanks! Good job folks!
Most helpful comment
@arunoda for posterity, the fix within
[email protected]does resolve this issue. Thank you!