Skip to content

TypeError: nanoid is not a function when using react native web and styled components #429

@eshankvaish

Description

@eshankvaish

This seems to be related to postcss/postcss#1727. So I was using react native on the web along with styled-components that use postcss. While everything was working as expected on Android and iOS but each time I tried using the app on the web, I kept on getting the error nanoid is not a function at https://github.com/postcss/postcss/blob/main/lib/input.js#L58. Upon debugging, I figured out that the nanoid version 3.3.6 was causing the issue due to breaking CJS support probably as mentioned in #422 as well. Upon adding the following resolutions to my package.json file, the error was finally resolved:

"resolutions": {
    "**/nanoid": "3.3.5"
}

Here is the link to a sample repository to reproduce the issue: https://github.com/eshankvaish/nanoid-issue and how I fixed the issue: https://github.com/eshankvaish/nanoid-issue/pull/1.

image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions