Skip to content
This repository was archived by the owner on Sep 2, 2023. It is now read-only.
This repository was archived by the owner on Sep 2, 2023. It is now read-only.

Feature: Import CommonJS without needing asynchronous syntax #116

@GeoffreyBooth

Description

@GeoffreyBooth

Split off from #114:

Updated feature request description:

Imagine code like this in current Node:

eval(fs.readFileSync('./underscore.min.js')); // Creates `_` variable in global scope
console.log(`Using Underscore version ${_.VERSION}`);

This can also be written as:

const _ = require('underscore'); // CommonJS module
console.log(`Using Underscore version ${_.VERSION}`);

Both of these examples are written without asynchronous syntax on the user’s part: there are no callbacks, no promises, no await. Perhaps Node is doing asynchronous stuff behind the scenes, but the user is unaware of it. require appears to be as synchronous as readFileSync.

This feature request is that a user’s code to import CommonJS modules via ESM should be like these examples: no callbacks, no promises, no await. This feature request doesn’t concern Node’s implementation under the hood, and whether it is synchronous or asynchronous; the request is only that the user’s code be able to be written in a synchronous style.

Use case 48. Part of #100.


Original feature request description:

ESM imports of CommonJS can be written in a synchronous style:

import { keys } from 'underscore'; // CommonJS package
const dateKeys = keys(Date);

The point of this feature is that users can use the same synchronous style of coding (in the vein of fs.readFileSync as opposed to callback- or promise-based alternatives) when the import is of CommonJS. Or put another way, users aren’t required to use await or promises or other asynchronous constructs in code in order to import CommonJS.

Use case 48. Part of #100.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions