Skip to content

SyntaxError: Identifier 'global' has already been declared while importing a json file with "global" key in SSR environment #17698

@korbinjoe

Description

@korbinjoe

Describe the bug

Error happened in a ssr vite react project while importing a json file as below:

index.tsx

import './test.json';

test.json

{
  "global": {
    "name": "全局"
  }
}

The error message is :

rror when evaluating SSR module /src/test.json:
|- SyntaxError: Identifier 'global' has already been declared
    at new AsyncFunction (<anonymous>)

Reproduction

https://github.com/korbinzhao/template-ssr-react-streaming-ts/blob/bug/ssr_json_global/src/App.tsx#L4

Steps to reproduce

No response

System Info

System:
    OS: macOS 13.5
    CPU: (8) arm64 Apple M1
    Memory: 173.59 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.11.1 - ~/.nvm/versions/node/v20.11.1/bin/node
    Yarn: 1.22.19 - ~/.yarn/bin/yarn
    npm: 10.2.4 - ~/.nvm/versions/node/v20.11.1/bin/npm
    pnpm: 8.14.1 - /opt/homebrew/bin/pnpm
  Browsers:
    Brave Browser: 102.1.39.111
    Chrome: 126.0.6478.127
    Edge: 114.0.1823.37
    Safari: 16.6

Used Package Manager

npm

Logs

No response

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    feat: ssrp3-minor-bugAn edge case that only affects very specific usage (priority)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions