Skip to content

5.1.x Regression - dynamic named import in dev mode not working as expected #16106

@n3dst4

Description

@n3dst4

Describe the bug

I am importing the library xss using a dynamic, named import, like this:

    const { FilterXSS } = await import("xss");
    const xss = new FilterXSS({});

I expect this to import the FilterXSS value from the xss library and call it as a constructor.

  • This works correctly in VIte 5.0.x in dev mode and production/preview mode.
  • It also works correctly in Vite 5.1 in production/preview mode.
  • However in Vite 5.1.x, in dev mode, FilterXSS is undefined.

Also worth noting:

  • Static default import import xss from "xss"; works fine in all situations.
  • Static named import import { FilterXSS } from "xss"; works fine in all situations.
  • Dynamic default import (await import("xss")).default also works fine in all situation.

Reproduction

https://github.com/n3dst4/vite-xss-import-bug-repro

Steps to reproduce

Clone the repo https://github.com/n3dst4/vite-xss-import-bug-repro

Install deps

pnpm install

To run in dev mode (to see the broken behavior):

pnpm dev

To run in production mode (wherein the bug does not manifest):

pnpm preview

System Info

System:                                                           
    OS: Linux 5.15 Ubuntu 22.04.3 LTS 22.04.3 LTS (Jammy Jellyfish) 
    CPU: (24) x64 AMD Ryzen 9 5900X 12-Core Processor               
    Memory: 25.44 GB / 31.31 GB                                     
    Container: Yes                                                  
    Shell: 5.8.1 - /usr/bin/zsh                                     
  Binaries:                                                         
    Node: 20.11.1 - ~/.nvm/versions/node/v20.11.1/bin/node          
    Yarn: 1.22.19 - ~/.nvm/versions/node/v20.11.1/bin/yarn          
    npm: 10.2.4 - ~/.nvm/versions/node/v20.11.1/bin/npm             
    pnpm: 8.15.0 - ~/.nvm/versions/node/v20.11.1/bin/pnpm           
  Browsers:                                                         
    Chromium: 122.0.6261.94                                         
  npmPackages:                                                      
    @vitejs/plugin-react-swc: ^3.5.0 => 3.6.0                       
    vite: ^5.1.5 => 5.1.5

Used Package Manager

pnpm

Logs

No response

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    p3-minor-bugAn edge case that only affects very specific usage (priority)regressionThe issue only appears after a new release

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions