Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test failures when testing with jest-styled-components #8692

Closed
vktrwlt opened this issue Mar 20, 2024 · 2 comments
Closed

Test failures when testing with jest-styled-components #8692

vktrwlt opened this issue Mar 20, 2024 · 2 comments

Comments

@vktrwlt
Copy link

vktrwlt commented Mar 20, 2024

Description

I'm currently exploring Bit for a project that utilizes styled-components and styled-systems, following a tutorial I found here. In setting up the project, I've integrated jest-styled-components for snapshot testing.

Interestingly, when I execute bit test, the snapshots are generated correctly with the extracted style rules. However, upon running bit build, the test step fails and the style rules aren't extracted anymore. The console leaves a multiple instances of 'styled-components' warning.

  It looks like there are several instances of 'styled-components' initialized in this application. This may cause dynamic styles to not render properly, errors during the rehydration process, a missing theme prop, and makes your application bigger without good reason. See https://s-c.sh/2BAXzed for more info.

I suspect this issue might be related to having multiple instances of styled-components in the project. I've attempted to resolve it by pinning versions and setting overrides to enforce a specific version, but the problem persists.

Any assistance or insights on this matter would be greatly appreciated.

Here is a link to my repo to reproduce the issue

Specifications

  • Bit version: 1.6.73
  • Node version: v20.10.0
  • Platform:
    -"@teambit/typescript.typescript-compiler": "^2.0.23",
  • "@teambit/defender.jest-tester": "^1.0.22",

Context and additional information

I tried pinning and adding a override to "teambit.dependencies/dependency-resolver"

 "teambit.dependencies/dependency-resolver": {
    "packageManager": "teambit.dependencies/pnpm",
    "policy": {
      "dependencies": {
        "styled-components": "5.3.11",
      },
    },
    "overrides": {
      "styled-components": "5.3.11"
    }
@itaymendel
Copy link
Contributor

Hi, to have a single instance of a dependency in your application it is recommended to set that dependency as a peerDependency, not as a dependency. This way the consuming app will know it should not install it, but instead resolve it from the root of node_modules.

@vktrwlt
Copy link
Author

vktrwlt commented Mar 22, 2024

hi @itaymendel, appreciate your help on looking into this.

Despite setting it as a peerDependency in my basic repository, I am still encountering the same issue. Within my barebone repository, I've only created one styled-component, and there isn't any consuming application, which is causing confusion regarding the error.

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

No branches or pull requests

2 participants