Skip to content

Rollup does not preserve order of imports after commonjs #3816

Closed
rollup/plugins
#1038
@danielgindi

Description

@danielgindi

Expected Behavior

All commonjsRegister calls should be at the top.
The commonjs plugin generates them at the top, and it should stay that way.

In cases of import from 'whatever', the import is clearly meant for causing a side effect, and thus it's order of execution matters.
(Of course it could be also in normal imports, but this case is very explicit and well known).

Actual Behavior

The order of imports generated by the commonjs plugin is not preserved, and other modules appear in between.
The result in some cases is that there's a call to commonjsRequire before the dynamic modules have been registered, so they it can't find/generate the module during the commonjsRequire call.

In this specific REPL you can see that between the commonjsRegister(...internal/wrapAsync) and commonjsRegister(...asyncify), there's one piece of code var setImmediate_1 = createCommonjsModule(...), which is extra weird since this variable is not in use yet, so why bump it to that position on top?

I know that rollup tends to manage the order of things by itself for the sake of optimization,
but we need to think of a way to at least specify cases where the user (or a plugin) requires a steady order of imports.
And perhaps detect those "side effect" imports and handle those automatically.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions