Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Bug]: json imports error with reserved keywords #6127

@marvinhagemeister

Description

@marvinhagemeister

Reproduction link or steps

https://repl.rolldown.rs/#eNptT81qwzAMfhWhSzco3t1jzzDY2ZfQ2CWbIwVb6TqC331y3fSHFnzwJ+n7WzCgXXCg3h+N5PontFe8xV2F48RJ4DszQUg8gkPzFphNnTh8d7Rjyhy9ibx/qcNXZXq0kmZftpg4xp5/yehZGPY3Rk82d5byN3lY4Ot89jnJoE5QWozNSt+0BAJNxj4QPmBxBMCzTLPYBgACp7FT6NDn0WEdFkf6HPnjyb/3oZvjqovaZa29NrjglvukrHqHLjqsyvxThQsW5R70IHbis2D5BymRgVE=

foo.json:

{
  "eval": "ok"
}

index.ts:

import json from "./foo.json";
console.log(json)

What is expected?

I expect no errors to be thrown.

What is actually happening?

This is the resulting code after passing it through rolldown:

//#region foo.json
var eval = "ok";
var foo_default = { eval };

//#endregion
//#region index.ts
console.log(foo_default);

//#endregion

And this happens when you run it.

node ./foo.mjs
file:///Users/marvinh/dev/rolldown-json-bug/foo.mjs:2
var eval = "ok";
    ^^^^

SyntaxError: Unexpected eval or arguments in strict mode
    at compileSourceTextModule (node:internal/modules/esm/utils:351:16)
    at ModuleLoader.moduleStrategy (node:internal/modules/esm/translators:107:18)
    at #translate (node:internal/modules/esm/loader:546:12)
    at ModuleLoader.loadAndTranslate (node:internal/modules/esm/loader:593:27)
    at async #link (node:internal/modules/esm/module_job:172:19)

System Info

System:
    OS: macOS 15.6.1
    CPU: (10) arm64 Apple M2 Pro
    Memory: 104.50 MB / 32.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 24.2.0 - ~/.nvm/versions/node/v24.2.0/bin/node
    Yarn: 1.22.22 - /opt/homebrew/bin/yarn
    npm: 11.3.0 - ~/.nvm/versions/node/v24.2.0/bin/npm
    pnpm: 10.15.1 - ~/Library/pnpm/pnpm
    Watchman: 2025.05.26.00 - /opt/homebrew/bin/watchman
  Browsers:
    Chrome: 139.0.7258.157
    Safari: 18.6

Any additional comments?

No response

Metadata

Metadata

Labels

No labels
No labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions