2

When i try to run react-native project via expo I get this error

E:/reacrNative23april/firestoreTester26April/node_modules/react-native/Libraries/StyleSheet/processColor.js
Module not found: Can't resolve '../Utilities/Platform' in 'E:\reacrNative23april\firestoreTester26April\node_modules\react-native\Libraries\StyleSheet'

This seems to be a common issue (as apparent through a google search), but appears to be unsolved.

There is some buzz on this link https://github.com/expo/web-examples/issues/73, but the solution is not clear.

Has anyone experienced and resolved this?

More data-

  1. Mine is a bare workflow project, with some native modules, not sure if they can be the issue
  2. I have tried deleteing the node_modules folder and running npm install, but no luck
grifterXcode
  • 109
  • 2
  • 6

1 Answers1

2

There is no non-native (i.e. web) version of Utilities/Platform in react-native.

You can create a webpack.config.js (expo has a helper for this) and add an alias for the relative reference to Utilities/Platform used from within various rn libraries to the one provided by react-native-web:

const createExpoWebpackConfigAsync = require('@expo/webpack-config');

module.exports = async function (env, argv) {
  const config = await createExpoWebpackConfigAsync(env, argv);
  // Customize the config before returning it.
  // Resolve relative reference ../Utilities/Platform using react-native-web
  config.resolve.alias['../Utilities/Platform'] = 'react-native-web/dist/exports/Platform';
  return config;
};
  • Are you sure about that? :) – Firas RG Jul 28 '22 at 09:26
  • Yes, although may have changed more recently, but react-native only had Platform.ios.js and Platform.android.js. This caused problems with some modules that import 'Libraries/Utilities/Platform' which would then not run in browser mode. React-native-web has a Platform.js, which you need to redirect to. We've moved over to flutter :) – Andy Clapham Aug 01 '22 at 09:25