Skip to content

Import statements are hoisted when target is CommonJs #1686

@petkaantonov

Description

@petkaantonov

Describe the bug

Import statements are hoisted when target is CommonJS:

import A from "a;
console.log(1);
import B from "a";

Becomes

require(...);
require(...);
console.log(1);

This is incorrect, require calls are normal functions and should have preserved order. Imports should only be hoisted when they are actual es6 imports. This is incompatible with tsc and probably others, tsc keeps the order as expected when output module is commonjs.

Additional context

It was fixed but then reverted in #1457

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions