Skip to content

v6.3.* causing crashes on react-native-web - nanoid is not a function #5705

Closed

Description

@marcobeltempo

Description

Related to: #4070

Reproducible example: https://github.com/marcobeltempo/expo-react-native-web-styled-components-test

Using styled-components 6.3* with react-native-web results in a silent warning during development and prevents the component from being styled correctly.

The issue originates from the postcss parse function, which is called within the generateStyleObject.

InlineStyle.ts:53 [styled-components/native] Failed to parse CSS: nanoid is not a function
n.generateStyleObject @ InlineStyle.ts:53
(anonymous) @ StyledNativeComponent.ts:76
E @ StyledNativeComponent.ts:117
react_stack_bottom_frame @ react-dom-client.development.js:25904
renderWithHooks @ react-dom-client.development.js:7662
updateForwardRef @ react-dom-client.development.js:9724
beginWork @ react-dom-client.development.js:12117
runWithFiberInDEV @ react-dom-client.development.js:871
performUnitOfWork @ react-dom-client.development.js:17641
workLoopSync @ react-dom-client.development.js:17469
renderRootSync @ react-dom-client.development.js:17450
performWorkOnRoot @ react-dom-client.development.js:16504
performWorkOnRootViaSchedulerTask @ react-dom-client.development.js:18957
performWorkUntilDeadline @ scheduler.development.js:45
<Styled(View)>

Expected Behaviour

Styled component applies the style.

Actual Behaviour

The component is unstyled, and a development console warning reports that nanoid is not a function.

Packages

{
    "expo": "~55.0.8",
    "expo-status-bar": "~55.0.4",
    "react": "19.2.0",
    "react-dom": "19.2.0",
    "react-native": "0.83.2",
    "react-native-web": "^0.21.0",
    "styled-components": "~6.3.12",
    "stylis": "~4.3.6"
}

Steps to reproduce

  1. git clone https://github.com/marcobeltempo/expo-react-native-web-styled-components-test.git
  2. cd expo-react-native-web-styled-components-test && npm install
  3. npm run web
  4. Open the browser dev tools to see the warning

Activity

  1. changed the title [-]v6.* causing crashes on react-native-web[/-] [+]v6.* causing crashes on react-native-web - nanoid is not a function[/+] on Mar 27, 2026
  2. changed the title [-]v6.* causing crashes on react-native-web - nanoid is not a function[/-] [+]v6.3.* causing crashes on react-native-web - nanoid is not a function[/+] on Mar 27, 2026
  3. quantizor commented on Mar 27, 2026

    @quantizor
    Contributor

    Thanks for the report and the repro repo, @marcobeltempo! This was a great catch.

    The root cause is that postcss unconditionally requires nanoid/non-secure at module load time, and Metro/Expo can't resolve it in react-native-web contexts — so the entire styled-components import fails before any CSS is even parsed.

    We've replaced postcss with a lightweight purpose-built CSS declaration parser for the React Native path. It's actually 2-3x faster than postcss for typical RN style declarations and handles all the edge cases (quoted strings, nested functions like calc()/var()/rgb(), data URIs, comments, etc.). This also removes postcss (along with nanoid and source-map-js) as a production dependency entirely.

    Fix is on main and will be included in the final 6.4.0 release, but is not in the current RC/prerelease builds. Will follow up here once it's published so you can verify.

  4. quantizor commented on Mar 28, 2026

    @quantizor
    Contributor

    Please try [email protected] when you get a moment, should fix the issue and be faster as well.

  5. mrossmaple commented on Mar 30, 2026

    @mrossmaple

    @quantizor @marcobeltempo I can confirm the issue is resolved on web with 6.4.0-prerelease.8 !

  6. marcobeltempo commented on Mar 30, 2026

    @marcobeltempo
    Author

    Thanks for the report and the repro repo, @marcobeltempo! This was a great catch.

    The root cause is that postcss unconditionally requires nanoid/non-secure at module load time, and Metro/Expo can't resolve it in react-native-web contexts — so the entire styled-components import fails before any CSS is even parsed.

    We've replaced postcss with a lightweight purpose-built CSS declaration parser for the React Native path. It's actually 2-3x faster than postcss for typical RN style declarations and handles all the edge cases (quoted strings, nested functions like calc()/var()/rgb(), data URIs, comments, etc.). This also removes postcss (along with nanoid and source-map-js) as a production dependency entirely.

    Fix is on main and will be included in the final 6.4.0 release, but is not in the current RC/prerelease builds. Will follow up here once it's published so you can verify.

    @quantizor Thank you for jumping on this so quickly!

    Glad the fix is in, and it’s great to hear you got a performance win out of it too. We pulled [email protected] and haven't had any issues so far.

    Thanks again!

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions