Skip to content

Conversation

@rturnq
Copy link

@rturnq rturnq commented Jun 6, 2025

Currently require calls for side effects only (eg. where exports are not used) get converted to a namespace import which fails when the imported module has no exports.

require("foo");

will become something like

import * as __CJS__import__1__ from "foo";

which will error when foo has no exports.

This PR adds support for require calls that are for side effects only by checking if the parent AST node of the require CallExpression is an ExpressionStatement and replacing that entire node with the side-effect import.

require("foo");

will become

import "foo";

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant