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

Vite SSR doesn't fail when same name is declared via import #19617

Open
7 tasks done
hi-ogawa opened this issue Mar 10, 2025 · 3 comments
Open
7 tasks done

Vite SSR doesn't fail when same name is declared via import #19617

hi-ogawa opened this issue Mar 10, 2025 · 3 comments
Labels
feat: ssr p2-edge-case Bug, but has workaround or limited in scope (priority) regression The issue only appears after a new release

Comments

@hi-ogawa
Copy link
Collaborator

hi-ogawa commented Mar 10, 2025

Describe the bug

Example code test.js

import { join } from "node:path";
import { join } from "node:path";

export default join("a", "b")

On Node:

 node src/test.js
SyntaxError: Identifier 'join' has already been declared (2:9)
    at ModuleLoader.moduleStrategy (https://kkvilbvzkqgithub-l0as.w-credentialless-staticblitz.com/builtins.8cb5228f.js:160:2071)
    at ModuleLoader.<anonymous> (https://kkvilbvzkqgithub-l0as.w-credentialless-staticblitz.com/builtins.8cb5228f.js:154:2546)
    at async https://kkvilbvzkqgithub-l0as.w-credentialless-staticblitz.com/builtins.8cb5228f.js:155:924

Node.js v18.20.3

On Vite SSR:

 node repro.js
[Module: null prototype] { default: 'a/b' }

I noticed this when testing oxc module runner transform in vitejs#85 where oxc rejected such code but current ssr tolerate the same code.

Reproduction

https://stackblitz.com/github/hi-ogawa/reproductions/tree/main/vite-ssr-import-name-already-declared?file=src%2Ftest.js

Steps to reproduce

Open stackblitz and run node repro.js and node src/test.js

System Info

System:
    OS: Linux 5.0 undefined
    CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 0 Bytes / 0 Bytes
    Shell: 1.0 - /bin/jsh
  Binaries:
    Node: 18.20.3 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 10.2.3 - /usr/local/bin/npm
    pnpm: 8.15.6 - /usr/local/bin/pnpm
  npmPackages:
    vite: ^6.2.0 => 6.2.1

Used Package Manager

npm

Logs

No response

Validations

@sapphi-red
Copy link
Member

This errors with Vite 4.5.9 (uses acorn):

Error: Parse failure: Identifier 'join' has already been declared (2:9)
At file: ./src/test.js
Contents of line 2: import { join } from "node:path";
    at ssrTransformScript (file:///home/projects/owainalwvo.github/node_modules/.pnpm/[email protected]/node_modules/vite/dist/node/chunks/dep-3936e161.js:55474:15)
    at ssrTransform (file:///home/projects/owainalwvo.github/node_modules/.pnpm/[email protected]/node_modules/vite/dist/node/chunks/dep-3936e161.js:55449:12)
    at Object.ssrTransform (file:///home/projects/owainalwvo.github/node_modules/.pnpm/[email protected]/node_modules/vite/dist/node/chunks/dep-3936e161.js:65323:20)
    at loadAndTransform (file:///home/projects/owainalwvo.github/node_modules/.pnpm/[email protected]/node_modules/vite/dist/node/chunks/dep-3936e161.js:55120:24)
    at async instantiateModule (file:///home/projects/owainalwvo.github/node_modules/.pnpm/[email protected]/node_modules/vite/dist/node/chunks/dep-3936e161.js:56006:10)

It's probably because acorn rejects these while SWC allows these.

@sapphi-red sapphi-red added feat: ssr p2-edge-case Bug, but has workaround or limited in scope (priority) regression The issue only appears after a new release labels Mar 10, 2025
@hi-ogawa
Copy link
Collaborator Author

By the similar token, this code doesn't fail on Vite SSR during module loading https://stackblitz.com/edit/github-tn8dri6l?file=src%2Ftest.js.

Example code

export { data }

On Node:

❯ node src/test.js
SyntaxError: Export 'data' is not defined (1:9)
    at ModuleLoader.moduleStrategy (https://owainalwvogithub-02gq.w-credentialless-staticblitz.com/builtins.8cb5228f.js:160:2071)
    at ModuleLoader.<anonymous> (https://owainalwvogithub-02gq.w-credentialless-staticblitz.com/builtins.8cb5228f.js:154:2546)
    at async https://owainalwvogithub-02gq.w-credentialless-staticblitz.com/builtins.8cb5228f.js:155:924

Node.js v18.20.3

On Vite SSR:

❯ node repro.js
[Module: null prototype] { data: [Getter] }

@sapphi-red
Copy link
Member

sapphi-red commented Mar 10, 2025

It seems that one is also rejected by acorn but not by SWC.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat: ssr p2-edge-case Bug, but has workaround or limited in scope (priority) regression The issue only appears after a new release
Projects
None yet
Development

No branches or pull requests

2 participants