callstack / callstack/haul

Module.createRequireFromPath() is deprecated.

Open
#746 0 comments 2 reactions 0 assignees View on GitHub
bug help wanted
Dominant language
TypeScript
Stars
3.7k
Forks
185
PR merge metrics
No merged PRs in 30d

Description

## Environment

Node v13.8.0

## Description

Module.createRequireFromPath() is deprecated since Node v12.2.0. An error is thrown when it is used on v13.

## Reproducible Demo

Use haul in a project with Node version > 13.

## Proposed fix

In https://github.com/callstack/haul/blob/d64efa45b30cd92026c9b5a595ed838db038b077/packages/haul-core/src/utils/importModule.ts#L88 something like the following could be implemented (to main compatibility with Node 10-12)

```
const createRequireWrapper = Module.createRequire || Module.createRequireFromPath
// Create resolver for this module.
const currentResolve = ((createRequireWrapper(
module.filename
) as unknown) as {
resolve: RequireResolve;
}).resolve;
```

The method seems to be identical in function, only its naming has changed.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.