Skip to content

RollupError: Identifier has already been declared #5259

@cheeaun

Description

@cheeaun

Rollup Version

4.5.0

Operating System (or Browser)

macOS Chrome

Node Version (if applicable)

v18

Link To Reproduction

https://rollupjs.org/repl/?version=4.5.0&shareable=JTdCJTIyZXhhbXBsZSUyMiUzQSUyMiUyMiUyQyUyMm1vZHVsZXMlMjIlM0ElNUIlN0IlMjJjb2RlJTIyJTNBJTIyY29uc3QlMjB0ZXN0JTIwJTNEJTIwZnVuY3Rpb24lMjBtYXhBcmdzKG1heEFyZ3MpJTIwJTdCJTdEJTVDbmV4cG9ydCUyMGRlZmF1bHQlMjB0ZXN0JTNCJTIyJTJDJTIyaXNFbnRyeSUyMiUzQXRydWUlMkMlMjJuYW1lJTIyJTNBJTIybWFpbi5qcyUyMiU3RCU1RCUyQyUyMm9wdGlvbnMlMjIlM0ElN0IlN0QlN0Q=

Expected Behaviour

The RollupError shouldn't happen. It didn't happen in previous Rollup v3.

Actual Behaviour

RollupError: Identifier "maxArgs" has already been declared shows up.

This started when I upgrade my project to Vite 5 which uses Rollup v4.2.0 (older than current one). Running the build task produces this error:

Screenshot 2023-11-20 at 5 35 26 PM

The error happens in a library called moize. The line referred is in src/index.ts (not the dist). This library generates the dist output with Rollup ^3.21.5. I've tried cloning the moize repo on my local machine, upgrades the Rollup version to v4.2.0, run the build step and can confirm the same error happens. I've also tried v4.5.0 and same error happens.

Screenshot 2023-11-20 at 5 47 37 PM

I've funneled it down to this shortest reproducible code on REPL ❌:

const test = function maxArgs(maxArgs) {}
export default test;

Here's 3 code examples that I can do to remove the error:

  1. REPL ✅ - Remove the const declaration
    function maxArgs(maxArgs) {}
    export default maxArgs;
  2. REPL ✅ - Remove the function name
    const test = function (maxArgs) {}
    export default test;
  3. REPL ✅ - Rename the argument name
    const test = function maxArgs(maxArgs2) {}
    export default test;

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions