[Web]Nx Project with reanimated and react-native-elements failed to build
See original GitHub issueDescription
We made an update from version 1.13.3 to 2.2.0 of the library. And since then, nothing is working as expected.
From a blank project, once added the dependencies, here is the error we have :
ERROR in …/…/node_modules/react-native-reanimated/lib/reanimated2/platform-specific/RNRenderer.js 3:0-90 Module not found: Error: Can’t resolve ‘react-native/Libraries/Renderer/shims/ReactNative’ in ‘F:\Projects\UMJ\mobile-web\node_modules\react-native-reanimated\lib\reanimated2\platform-specific’
Just to give detailled context, we are using nx in a monorepo project. For the web part, please find below the webpack.js config :
const getWebpackConfig = require('@nrwl/react/plugins/webpack');
const path = require('path')
function getCustomWebpackConfig(webpackConfig) {
const config = getWebpackConfig(webpackConfig);
const isProduction = webpackConfig.mode === 'production';
if (!isProduction) {
config.resolve.alias = {
'react-native': 'react-native-web',
};
config.module.rules.push(
{
test: /\.ttf$/,
loader: require.resolve('file-loader'),
include: [
path.resolve(__dirname, "../../node_modules/react-native-vector-icons")
],
options: { esModule: false, name: 'static/media/[path][name].[ext]' },
},
{
test: /\.(gif|jpeg|jpg|png|svg)$/,
use: {
loader: "url-loader",
options: {
name: "[name].[ext]",
esModule: false,
}
}
},
{
test: /\.(js|jsx)$/,
include: [
path.resolve(__dirname, "src/"),
path.resolve(__dirname, "../../node_modules/deepmerge/"),
path.resolve(__dirname, "../../node_modules/react-native-vector-icons/"),
path.resolve(__dirname, "../../node_modules/react-native-elements/"),
path.resolve(__dirname, "../../node_modules/react-native-ratings/"),
path.resolve(__dirname, "../../node_modules/react-native-reanimated/")
],
use: {
loader: require.resolve('@nrwl/web/src/utils/web-babel-loader.js'),
options: {
presets: [
[
'@nrwl/react/babel',
{
runtime: 'automatic',
useBuiltIns: 'usage',
},
],
],
plugins: ['react-native-web'],
},
},
}
);
}
return {
...config,
node: { global: true }, // Fix: "Uncaught ReferenceError: global is not defined", and "Can't resolve 'fs'".
};
}
module.exports = getCustomWebpackConfig;
and the .babelrc configuration :
{
"presets": [
[
"@nrwl/react/babel",
{
"runtime": "automatic"
}
]
],
"plugins": []
}
Expected behavior
The project compile fine.
Actual behavior & steps to reproduce
The actual behavior is to have the above errors.
Snack or minimal code example
Just start a fresh NX project and add a application. Here are the commands :
- Create the workspace
npx create-nx-workspace sample --preset=react-native
- Create the application
nx generate application website
Package versions
Here are the list of my dependencies :
{package|version|
| core-js | 3.6.5 |
| install | 0.13.0 |
| npm | 8.1.1 |
| react | 17.0.2 |
| react-dom | 17.0.2 |
| react-native | 0.66.1 |
| react-native-elements | 3.4.2 |
| react-native-gesture-handler | 1.10.3 |
| react-native-ratings | 8.1.0 |
| react-native-reanimated | 2.2.0 |
| react-native-safe-area-context | 3.2.0 |
| react-native-screens | 3.3.0 |
| react-native-svg | 12.1.1 |
| react-native-svg-transformer | 0.14.3 |
| react-native-style-tachyons | 4.2.0 |
| react-native-vector-icons | 8.1.0 |
| @react-navigation/drawer | 6.1.8 |
| @react-navigation/native | 6.0.6 |
| @react-navigation/native-stack | 6.2.5 |
| react-native-web | 0.17.5 |
| regenerator-runtime | 0.13.7 |
| tslib | 2.0.0 |
I’m using Java 11 but this is not related to the bug because the mobile version of the application work perfectly fine.
Affected platforms
- Android
- iOS
- Web
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (4 by maintainers)
Similar issue for me in a monorepo on
2.2.3
. Downgrading to2.2.2
and clearing all caches solves it (deleted.expo
,ios
,node_modules
).Important to put
"2.2.2"
and not"^2.2.0"
This is what happened when I ran
expo run:ios
Thanks If there are any more problems please let us know