Skip to content

Fix os and tty modules being emptied with Expo API Routes#876

Open
Nezz wants to merge 1 commit intostorybookjs:nextfrom
Nezz:fix/ExpoApiRoutes
Open

Fix os and tty modules being emptied with Expo API Routes#876
Nezz wants to merge 1 commit intostorybookjs:nextfrom
Nezz:fix/ExpoApiRoutes

Conversation

@Nezz
Copy link
Copy Markdown

@Nezz Nezz commented Apr 11, 2026

Issue: withStorybook replaces os and tty with empty modules on all platforms, breaking Expo API Routes

What I did

withStorybook unconditionally resolved os and tty to { type: "empty" } as a workaround. This breaks Expo API Routes (which bundle for the web platform) when any server-side dependency needs real Node built-ins like os.hostname().

Changes:

  • Enabled path: Scoped the os/tty empty-module override to native platforms only (platform !== 'web'), so web/server bundles get the real Node modules.
  • Disabled path: Removed the os/tty override entirely. When Storybook is disabled, all storybook/@storybook imports are already emptied, so the instrumentor is never loaded and its os/tty imports are never reached.
  • Added tests covering both behaviors.

How to test

  1. Set up an Expo project with API Routes and @storybook/react-native
  2. In an API route, use any library that calls require("os") (e.g. os.hostname())
  3. Verify the API route works without os.hostname is not a function errors
  4. Verify Storybook still loads correctly on iOS/Android (the os/tty override still applies on native platforms)
  • Does this need a new example in examples/expo-example? No
  • Does this need an update to the documentation? No

If your answer is yes to any of these, please make sure to include it in your PR.

@Nezz Nezz requested a review from dannyhw as a code owner April 11, 2026 07:11
@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Apr 11, 2026

⚠️ No Changeset found

Latest commit: c3941f5

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

return {
type: 'empty',
};
}
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The intention behind doing this when storybook is disabled wasn't clear to me, but this could be re-added if needed with the web check

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its because I had some reports of these packages getting pulled in somehow even when storybook was disabled

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh wow, not sure how that could happen 😅

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah i don't know, just metro things 😅

@dannyhw
Copy link
Copy Markdown
Member

dannyhw commented Apr 11, 2026

Makes sense, thanks for the pr 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants