Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

135
Vistas
How can I use emotion with react-native-web?

I develop a cross-platform react-native application inside a monorepo and want to render my app using react-native-web in the browser. To achieve that I followed this guide https://mmazzarolo.com/blog/2021-09-22-running-react-native-everywhere-web/. I'm also using the metro-react-native-babel-preset package for compiling my web-app, as described in the react-native-web guide https://necolas.github.io/react-native-web/docs/multi-platform/. Here is a part of my craco.config.js file (I use create-react-app with craco):

// craco.config.js
const webpack = require("webpack");
const { getWebpackTools } = require("react-native-monorepo-tools");

const monorepoWebpackTools = getWebpackTools();

module.exports = {
  babel: {
    presets: ["module:metro-react-native-babel-preset", "@babel/preset-react"]
  },
  webpack: {
    configure: (webpackConfig) => {
      // Allow importing from external workspaces.
      monorepoWebpackTools.enableWorkspacesResolution(webpackConfig);
      // Ensure nohoisted libraries are resolved from this workspace.
      monorepoWebpackTools.addNohoistAliases(webpackConfig);
      return webpackConfig;
    },

Now it seems like the metro-react-native-babel-preset preset is not compatible with the stylis library (imported by @emotion/react), because I get this error when launching the app in the browser (it compiles without errors):

Uncaught TypeError: (0 , _stylis.middleware) is not a function
    at createCache (emotion-cache.browser.esm.js:288)
    at Object.../node_modules/@emotion/react/dist/emotion-element-699e6908.browser.esm.js (emotion-element-699e6908.browser.esm.js:11)
    at __webpack_require__ (bootstrap:851)
    at fn (bootstrap:150)
    at Object.<anonymous> (emotion-react.browser.esm.js:3)
    at Object.../node_modules/@emotion/react/dist/emotion-react.browser.esm.js (emotion-react.browser.esm.js:347)
    at __webpack_require__ (bootstrap:851)
    at fn (bootstrap:150)
    at Object.../node_modules...

I guess that the stylis-package cannot be imported correctly due to the metro-react-native-babel-preset preset, since without the preset the error is gone (but the compilation-step throws errors, so removing the preset is not a solution).

What do I have to change in my babel- / webpack-config or code to remove this error?

Minimum, reproducible example

https://github.com/Tracer1337/stackoverflow-mre

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

I think it is a problem with packages version.

When I try it, I also have this error.

But when updated packages to newer version it was gone (other error occured thought, but related to reactDOM).

I have updated react-scripts to 5.0.0;

See if it helps you as well.

{
  "name": "@meme-bros/web",
  ...
  "dependencies": {
    "@emotion/react": "^11.7.1",
    "@emotion/styled": "^11.6.0",
    "@mui/material": "^5.2.3",
    "@types/react": "^17.0.0",
    "@types/react-dom": "^17.0.0",
    "metro-react-native-babel-preset": "^0.66.2",
    "react": "^17.0.2",
    "react-dom": "^17.0.2",
    "react-native-web": "^0.17.5",
    "react-scripts": "5.0.0",
    "typescript": "^4.1.2"
  },
  "devDependencies": {
    "@craco/craco": "^6.4.3",
    "react-native-monorepo-tools": "^1.1.4"
  },
 ...
about 4 years ago · Juan Pablo Isaza Denunciar

0

Would you mind to follow these guidelines to run React Native app on web. Official Doc

And Add @emotion/react in compileNodeModules list

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda