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

Issue when importing default from module on SSR #10712

Closed
7 tasks done
adrifer opened this issue Oct 30, 2022 · 1 comment
Closed
7 tasks done

Issue when importing default from module on SSR #10712

adrifer opened this issue Oct 30, 2022 · 1 comment

Comments

@adrifer
Copy link

adrifer commented Oct 30, 2022

Describe the bug

Hello,

I'm working on a Typescript SSR React app on Vite. I'm having an issue with several modules when importing default property from the module.

The issue is when I'm trying to import default from module like:
import loadable from "@loadable/component";
or
import styled from "styled-components";

Both of them are default exports. On the client works perfectly but on SSR I get something like Error: _loadable_component.default is not a function. Then to make it work on SSR I need to do something like loadable.default or styled.default.

I found a workaround for this, but I don't think this is the way to go: styled-components/styled-components#3832 (comment)

Is there anything I'm missing? Thanks in advance!

Reproduction

https://stackblitz.com/edit/vitejs-vite-kb6oam?file=package.json

Steps to reproduce

The steps are:
yarn install
yarn start

System Info

  System:
    OS: Windows 10 10.0.22000
    CPU: (32) x64 AMD Ryzen 9 5950X 16-Core Processor
    Memory: 24.01 GB / 63.93 GB
  Binaries:
    Node: 16.13.1 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.19 - C:\Program Files\nodejs\yarn.CMD
    npm: 8.1.2 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Edge: Spartan (44.22000.120.0), Chromium (106.0.1370.52)
    Internet Explorer: 11.0.22000.120
  npmPackages:
    @vitejs/plugin-react: ^2.2.0 => 2.2.0 
    vite: ^3.2.0 => 3.2.1

Used Package Manager

yarn

Logs

No response

Validations

@bluwy
Copy link
Member

bluwy commented Nov 9, 2023

Should be fixed in #14521. Make sure the way you import also works in Node too as Vite follows the behaviour.

@bluwy bluwy closed this as completed Nov 9, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Nov 24, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants