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

Fix plain NodeJS usage #4268

Open
gabriel-naressi opened this issue Feb 29, 2024 · 1 comment
Open

Fix plain NodeJS usage #4268

gabriel-naressi opened this issue Feb 29, 2024 · 1 comment

Comments

@gabriel-naressi
Copy link

gabriel-naressi commented Feb 29, 2024

Environment

## System:
 - OS: macOS 14.3.1
 - CPU: (8) arm64 Apple M1
 - Memory: 91.42 MB / 8.00 GB
 - Shell: 3.2.57 - /bin/bash
## Binaries:
 - Node: 16.20.2 - ~/.nvm/versions/node/v16.20.2/bin/node
 - Yarn: 3.5.1 - ~/.nvm/versions/node/v16.20.2/bin/yarn
 - npm: 8.19.4 - ~/.nvm/versions/node/v16.20.2/bin/npm
## npmPackages:
 - styled-components: ^6.1.8 => 6.1.8

Reproduction

https://stackblitz.com/edit/vitest-dev-vitest-mt2ebd?file=repro.mjs

Steps to reproduce

The reproduction is on the stackblitz link

Expected Behavior

NodeJS usage should be possible. This became an issue following a comment from one of the vite maintainers in this thread: vitest-dev/vitest#5286 (reply in thread).

Another useful link that shows the problem: https://publint.dev/[email protected]

Actual Behavior

import styled from 'styled-components';

console.log('keys:', Object.keys(styled));
console.log('styled.h1', styled.h1); // undefined
console.log('styled.default.h1', styled.default.h1); // function
@shayvt
Copy link

shayvt commented May 8, 2024

I came here from the issue on vitest repo.
The NodeJS usage is important for vitest to run with styled-components, since vitest run in the context of node.

The workaround from the vitest issue that worked also for me is to add the private package that depends on styled-components to test.server.deps.inline:

// vite.config.ts
export default defineConfig({
  test: {
    server: {
      deps: {
        inline: ["replace-with-your-package"],
      }
    }
  },
});

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

No branches or pull requests

2 participants