tamagui: Error when running yarn ios using starters

Current Behavior

using npm create tamagui@latest --template expo-router and follow the steps to create a project, then run yarn ios to start development via expo go or expo-dev-client, the same error is encountered in both ways

 ERROR  ReferenceError: Property 'document' doesn't exist, js engine: hermes
    at ContextNavigator (http://localhost:8081/node_modules/expo-router/entry.bundle//&platform=ios&dev=true&lazy=true&minify=false&inlineSourceMap=false&modulesOnly=false&runModule=true&app=com.anonymous.expo-router-example&transform.routerRoot=app&transform.engine=hermes:148411:24)
    at ExpoRoot (http://localhost:8081/node_modules/expo-router/entry.bundle//&platform=ios&dev=true&lazy=true&minify=false&inlineSourceMap=false&modulesOnly=false&runModule=true&app=com.anonymous.expo-router-example&transform.routerRoot=app&transform.engine=hermes:148367:28)
    at App
    at ErrorToastContainer (http://localhost:8081/node_modules/expo-router/entry.bundle//&platform=ios&dev=true&lazy=true&minify=false&inlineSourceMap=false&modulesOnly=false&runModule=true&app=com.anonymous.expo-router-example&transform.routerRoot=app&transform.engine=hermes:341210:24)
    at ErrorOverlay
    at withDevTools(ErrorOverlay) (http://localhost:8081/node_modules/expo-router/entry.bundle//&platform=ios&dev=true&lazy=true&minify=false&inlineSourceMap=false&modulesOnly=false&runModule=true&app=com.anonymous.expo-router-example&transform.routerRoot=app&transform.engine=hermes:340744:27)
    at RCTView
    at View (http://localhost:8081/node_modules/expo-router/entry.bundle//&platform=ios&dev=true&lazy=true&minify=false&inlineSourceMap=false&modulesOnly=false&runModule=true&app=com.anonymous.expo-router-example&transform.routerRoot=app&transform.engine=hermes:40740:43)
    at RCTView
    at View (http://localhost:8081/node_modules/expo-router/entry.bundle//&platform=ios&dev=true&lazy=true&minify=false&inlineSourceMap=false&modulesOnly=false&runModule=true&app=com.anonymous.expo-router-example&transform.routerRoot=app&transform.engine=hermes:40740:43)
    at AppContainer (http://localhost:8081/node_modules/expo-router/entry.bundle//&platform=ios&dev=true&lazy=true&minify=false&inlineSourceMap=false&modulesOnly=false&runModule=true&app=com.anonymous.expo-router-example&transform.routerRoot=app&transform.engine=hermes:40551:36)
    at main(RootComponent) (http://localhost:8081/node_modules/expo-router/entry.bundle//&platform=ios&dev=true&lazy=true&minify=false&inlineSourceMap=false&modulesOnly=false&runModule=true&app=com.anonymous.expo-router-example&transform.routerRoot=app&transform.engine=hermes:124413:28)

and then a same error is repeated continuously

λ Bundled 6992ms (node_modules/expo-router/node/render.js)
Web Bundled 7092ms (node_modules/expo-router/entry.js)
λ  WARN  props.pointerEvents is deprecated. Use style.pointerEvents
λ  WARN  "shadow*" style props are deprecated. Use "boxShadow".
 styleq (node_modules/styleq/dist/styleq.js:62:39)
λ  WARN  accessibilityRole is deprecated. Use role.
λ  WARN  accessibilityLabel is deprecated. Use aria-label.
λ  WARN  Image: style.resizeMode is deprecated. Please use props.resizeMode.
λ  WARN  Image: style.tintColor is deprecated. Please use props.tintColor.
ERROR  There was a problem connecting to the react-native-css-interop Metro server
image

Expected Behavior

start the project on expo go or expo-dev-client without error

Tamagui Version

1.89.26

Platform (Web, iOS, Android)

iOS

Reproduction

Expo go steps:
1. run `npm create tamagui@latest --template expo-router`
2. select `Expo Router (beta) - Expo Router starter with Tamagui set up`
3. `cd` into the project and run `yarn ios`
4. press `i` to expo-go app in iOS simulator

Dev build step
1. run `npm create tamagui@latest --template expo-router`
2. select `Expo Router (beta) - Expo Router starter with Tamagui set up`
3. run `npx expo run:ios` to create a dev build
4. upon build succeeded, press `i` to launch dev build in iOS simulator

System Info

System:
    OS: macOS 14.2.1
    CPU: (10) arm64 Apple M1 Pro
    Memory: 4.32 GB / 32.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 21.1.0 - ~/.nvm/versions/node/v21.1.0/bin/node
    Yarn: 4.0.2 - ~/.nvm/versions/node/v21.1.0/bin/yarn
    npm: 10.2.0 - ~/.nvm/versions/node/v21.1.0/bin/npm
    pnpm: 8.14.1 - /opt/homebrew/bin/pnpm
    bun: 1.0.26 - ~/.bun/bin/bun
    Watchman: 2023.12.04.00 - /opt/homebrew/bin/watchman
  Browsers:
    Brave Browser: 119.1.60.118
    Chrome: 121.0.6167.184
    Safari: 17.2.1
  npmPackages:
    @babel/core: ^7.23.3 => 7.23.9
    @expo/metro-runtime: ~3.1.3 => 3.1.3
    @react-navigation/native: ^6.0.2 => 6.1.10
    @tamagui/config: ^1.89.26 => 1.89.26
    @tamagui/metro-plugin: ^1.89.26 => 1.89.26
    @types/react: ~18.2.14 => 18.2.55
    babel-preset-expo: ^10.0.1 => 10.0.1
    expo: ~50.0.6 => 50.0.6
    expo-font: ~11.10.2 => 11.10.2
    expo-linking: ~6.2.1 => 6.2.2
    expo-router: ~3.4.7 => 3.4.7
    expo-splash-screen: ~0.26.4 => 0.26.4
    expo-status-bar: ~1.11.1 => 1.11.1
    expo-system-ui: ~2.9.3 => 2.9.3
    expo-web-browser: ~12.8.2 => 12.8.2
    react: ^18.2.0 => 18.2.0
    react-dom: ^18.2.0 => 18.2.0
    react-helmet-async: ~2.0.4 => 2.0.4
    react-native: 0.73.4 => 0.73.4
    react-native-reanimated: ~3.6.2 => 3.6.2
    react-native-safe-area-context: 4.8.2 => 4.8.2
    react-native-screens: ~3.29.0 => 3.29.0
    react-native-web: ^0.19.9 => 0.19.10
    tamagui: ^1.89.26 => 1.89.26
    typescript: ^5.3.3 => 5.3.3

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 12
  • Comments: 36 (11 by maintainers)

Most upvoted comments

Same here image

I’ll check that over weekend

if you want to add Tamagui to an existing project make sure to follow Tamagui expo router starter and apply same changes! as this tamagui starter is working fine, I’ll close this issue as done

@rlee1990 That’s because you’re using import Instead, try:

if (Platform.OS === 'web') {
  require('../tamagui-web.css')
}

I’m getting the error if I add import '@tamagui/core/reset.css'; or import '../tamagui-web.css'; into app/_layout.tsx

If I delete that, the error is gone.

I’m still experiencing the same issue with the import '../tamagui-web.css' despite upgrading my Tamagui version

There is a fix for windows users on master branch, and will be available with next release

@TheEhsanSarshar I created a new Expo project with npx create-expo-app --template (File based router), then followed the instructions on https://tamagui.dev/docs/guides/expo to add Tamagui to the project, and I’m getting the same endless stream of There was a problem connecting to the react-native-css-interop Metro server in the console.

Here’s my example project: https://github.com/kasparas-ban/tamagui-test

Upgrading to 1.90.6 resolved my issue

this error still keeps repeating in the terminal: ERROR There was a problem connecting to the react-native-css-interop Metro server

Same issue here🙋 My workaround is comment this line in app/_layout.tsx:

// import '../tamagui-web.css';

I just upgraded to the latest 1.102.2 tamagui suite version, nothing changes.

expo sdk version is 51.0.21

@ddikodroid +1 on removing the css imports.

this issue should be re-opened.

error i got before removing:

iOS Bundling failed 9500ms (node_modules/expo-router/entry.js)
Unable to resolve "react-native-reanimated" from "node_modules/react-native-css-interop/dist/runtime/native/utils.js"

Got the same problem when running the project on macos with version 1.90.14. The same result after updating to the newest version 1.91.3. - Any workarounds? On Windows it works with 1.90.14 - with 1.91.3 haven’t tested yet.

I created the project using command from tamagui official website npm create tamagui@latest --template expo-router

@TheEhsanSarshar Yes. I’ve tested this in every which way I could think of: on native, on web, on iOS and Android, using yarn and npm. Still the same error. I’m a bit surprised that not more people are getting this. I’ve used nothing but the official template and the exact instructions from the docs. Are you able to reproduce it? .

I got the same problem, with template created 2 days ago My workaround was to dynamically import the css in app/_layout.tsx:

import { Platform } from "react-native";

if (Platform.OS === "web") {
  import("../tamagui-web.css");
}

And the application seems to work fine in android. At least the error doesn’t show. But I don’t know how this impact in tamagui correct functionality.

TL;DR

I just solved the ERROR There was a problem connecting to the react-native-css-interop Metro server adding at the end of metro.config.js file:

module.exports = config

Explanation

I had my project already created with default’s Expo template, so I had to configure Tamagui from scratch. I followed the official tamagui expo guide. I did eeeverything exactly as says, but unfortunately I ran into that anoying metro error.

Reading your responses here, I saw some of you pointing out that the latest Tamagui expo template had no issues, so I just created one and compared with mine.

After adding Tamagui Metro’s config to my metro.config.js, it looked like this:

// Learn more https://docs.expo.io/guides/customizing-metro
/**
 * @type {import('expo/metro-config').MetroConfig}
 */
const { getDefaultConfig } = require('expo/metro-config');

const config = getDefaultConfig(__dirname, {
  // [Web-only]: Enables CSS support in Metro.
  isCSSEnabled: true,
});

// Add Tamagui support with optimizing compiler + CSS extraction
const { withTamagui } = require('@tamagui/metro-plugin');
module.exports = withTamagui(config, {
  components: ['tamagui'],
  config: './tamagui.config.ts',
  outputCSS: './tamagui-web.css',
});

And the only difference with Tamagui’s template were two lines:

config.resolver.sourceExts.push('mjs')
module.exports = config

I don’t know what they do nor where they come from, I just did some testing with one and another line, and I could prove that the solution was the module.exports = config. In case you wonder what I did with the other line config.resolver.sourceExts.push('mjs'), I am leaving it anyway just in case 😃

Hope that helps you!

same issue,

"expo": "~51.0.17",
"tamagui": "^1.101.5"

does anyone know stable solution?

UPDATE: if you see similar error with this .css file, try to update bebel.config.js

module.exports = (api) => {
  api.cache(true)
  return {
    presets: [['babel-preset-expo', { jsxRuntime: 'automatic' }]],
    plugins: [
      [
        '@tamagui/babel-plugin',
        {
          components: ['tamagui'],
          config: './tamagui.config.ts',
          importsWhitelist: ['constants.js', 'colors.js'],
          logTimings: true,
          disableExtraction: process.env.NODE_ENV === 'development',
        },
      ],

      // NOTE: this is only necessary if you are using reanimated for animations
      'react-native-reanimated/plugin',
    ],
  }
}

also, add in metro.config.js

config.resolver.sourceExts.push('mjs')

I had the ERROR ReferenceError: Property 'document' doesn't exist, js engine: hermes too. I don’t know if the reasons are the same, but I found out that there is a file node_modules/@tamagui/constants/dist/esm/index.mjs that exports "./constants.mjs". The constants file is where a variable named isClient is defined. But exporting "./constants.mjs" (where isClient is set to true) makes the resolver ignoring the "./constants.native.mjs" (where isClient is set to false). Replacing export * from "./constants.mjs"; by export * from "./constants"; fixed this error for me.

Update

Instead of patching the dependency, I wrote a custom resolver for Metro:

config.resolver.resolveRequest = (context, moduleName, platform) => {
  if (
    moduleName === './constants.mjs'
    && context.originModulePath.includes('node_modules/@tamagui/constants/dist/esm/index.mjs')
    && ['ios', 'android'].includes(platform)
  ) {
    return context.resolveRequest(context, './constants.native.mjs', platform);
  }

  return context.resolveRequest(context, moduleName, platform);
}

I know this is pretty frustrating for maintainers to ear because it is more of the same. However, I too am getting this issue. Unfortunatly, I can’t give you much context as I am new to React-Native/Expo/Tamagui ecosystem. I was just following along with a YouTube course and decide to use tamagui instead of NativeWind when they suggested adding the style system. The reason simple being, I am looking forward to use Tamagui in the future and because I felt very comfortable with PandaCSS in ionic and web land.

Like some users above, I only have this problem when I add web and css imports in app/_layout.tsx. The solution proposed by @giornn0 worked for me. Since my package.json does not explicitly set "type": "module" and my tsconfig.json does not set the "module" property. I had to use require statements instead.

Would this cause uninteded side-effects on Tamagui?

if (Platform.OS === 'web') {
  require('@tamagui/core/reset.css')
  require('../assets/styles/tamagui-web.gen.css')
}

although I wasn’t able to reproduce it with Tamagui official starter, yeah I’ll check it again, maybe something is broken since then