Skip to content

feature request: createRequire detect #14228

@Jack-Works

Description

@Jack-Works

Feature request

What is the expected behavior?

For code like below:

import { createRequire as _createRequire } from 'module'
const __require = _createRequire(import.meta.url)

__require should be detected as an alias of CommonJS require and the imported module of __require should be the type of javascript/auto instead of javascript/esm.

What is motivation or use case for adding/changing the behavior?

This allows webpack to bundle this format of ESModule projects.

And TypeScript is going to add Node-12 module emit which will generate code like above.

How should this be implemented in your opinion?

Detect import of module module and track the pattern of const $requireAlias = $importedCreateRequire(import.meta.url).

Are you willing to work on this yourself?
yes but I'm not familiar with webpack internal.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions