-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Closed
Labels
Milestone
Description
Describe the feature
TypeScript's new module: nodenext
will emit const require = createRequire()
as necessary in ESM modules that have import =
syntax. Without calling createRequire()
, the code fails, because require
is not defined in ES modules on nodejs.
import commonjs = require('commonjs');
import * as ecmascriptmodule from 'ecmascriptmodule';
commonjs, ecmascriptmodule;
When compiled by SWC using target=es2022 and module=es modules, I get: (playground link)
const commonjs = require('commonjs');
import * as ecmascriptmodule from 'ecmascriptmodule';
commonjs, ecmascriptmodule;
However, TypeScript will include a call to createRequire
: (playground link)
import { createRequire as _createRequire } from "module";
const __require = _createRequire(import.meta.url);
const commonjs = __require("commonjs");
import * as ecmascriptmodule from 'ecmascriptmodule';
commonjs, ecmascriptmodule;
Is there any way to tell SWC to emit this createRequire
call?
Babel plugin or link to the feature description
No response
Additional context
No response
millsp