callstack / haul

Haul is a command line tool for developing React Native apps, powered by Webpack
MIT License
3.64k stars 194 forks source link

Module.createRequireFromPath() is deprecated. #746

Open sraka1 opened 4 years ago

sraka1 commented 4 years ago

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.