Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

module: remove module.createRequireFromPath #37201

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions doc/api/deprecations.md
Original file line number Diff line number Diff line change
Expand Up @@ -2379,6 +2379,9 @@ instead.
### DEP0130: `Module.createRequireFromPath()`
<!-- YAML
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/37201
description: End-of-life.
- version: v13.0.0
pr-url: https://github.com/nodejs/node/pull/27951
description: Runtime deprecation.
Expand All @@ -2387,10 +2390,9 @@ changes:
description: Documentation-only.
-->

Type: Runtime
Type: End-of-Life

Module.createRequireFromPath() is deprecated. Please use
[`module.createRequire()`][] instead.
Use [`module.createRequire()`][] instead.

### DEP0131: Legacy HTTP parser
<!-- YAML
Expand Down
21 changes: 0 additions & 21 deletions doc/api/module.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,26 +56,6 @@ const require = createRequire(import.meta.url);
const siblingModule = require('./sibling-module');
```

### `module.createRequireFromPath(filename)`
<!-- YAML
added: v10.12.0
deprecated: v12.2.0
-->

> Stability: 0 - Deprecated: Please use [`createRequire()`][] instead.

* `filename` {string} Filename to be used to construct the relative require
function.
* Returns: {require} Require function

```js
const { createRequireFromPath } = require('module');
const requireUtil = createRequireFromPath('../src/utils/');

// Require `../src/utils/some-tool`
requireUtil('./some-tool');
```

### `module.syncBuiltinESMExports()`
<!-- YAML
added: v12.12.0
Expand Down Expand Up @@ -211,7 +191,6 @@ consists of the following keys:
[`--enable-source-maps`]: cli.md#cli_enable_source_maps
[`NODE_V8_COVERAGE=dir`]: cli.md#cli_node_v8_coverage_dir
[`SourceMap`]: #module_class_module_sourcemap
[`createRequire()`]: #module_module_createrequire_filename
[`module`]: modules.md#modules_the_module_object
[module wrapper]: modules.md#modules_the_module_wrapper
[source map include directives]: https://sourcemaps.info/spec.html#h.lmz475t4mvbx
1 change: 0 additions & 1 deletion doc/api/modules.md
Original file line number Diff line number Diff line change
Expand Up @@ -966,7 +966,6 @@ This section was moved to
<!-- Anchors to make sure old links find a target -->
* <a id="modules_module_builtinmodules" href="module.html#module_module_builtinmodules">`module.builtinModules`</a>
* <a id="modules_module_createrequire_filename" href="module.html#module_module_createrequire_filename">`module.createRequire(filename)`</a>
* <a id="modules_module_createrequirefrompath_filename" href="module.html#module_module_createrequirefrompath_filename">`module.createRequireFromPath(filename)`</a>
* <a id="modules_module_syncbuiltinesmexports" href="module.html#module_module_syncbuiltinesmexports">`module.syncBuiltinESMExports()`</a>

## Source map v3 support
Expand Down
7 changes: 0 additions & 7 deletions lib/internal/modules/cjs/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -1184,13 +1184,6 @@ function createRequireFromPath(filename) {
return makeRequireFunction(m, null);
}

Module.createRequireFromPath = deprecate(
createRequireFromPath,
'Module.createRequireFromPath() is deprecated. ' +
'Use Module.createRequire() instead.',
'DEP0130'
);

const createRequireError = 'must be a file URL object, file URL string, or ' +
'absolute path string';

Expand Down
5 changes: 2 additions & 3 deletions test/es-module/test-esm-json-cache.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ import '../common/index.mjs';

import { strictEqual, deepStrictEqual } from 'assert';

import { createRequireFromPath as createRequire } from 'module';
import { fileURLToPath as fromURL } from 'url';
import { createRequire } from 'module';

import mod from '../fixtures/es-modules/json-cache/mod.cjs';
import another from '../fixtures/es-modules/json-cache/another.cjs';
import test from '../fixtures/es-modules/json-cache/test.json';

const require = createRequire(fromURL(import.meta.url));
const require = createRequire(import.meta.url);

const modCjs = require('../fixtures/es-modules/json-cache/mod.cjs');
const anotherCjs = require('../fixtures/es-modules/json-cache/another.cjs');
Expand Down
18 changes: 0 additions & 18 deletions test/parallel/test-module-create-require-from-directory.js

This file was deleted.

5 changes: 1 addition & 4 deletions test/parallel/test-module-create-require.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,11 @@ require('../common');
const assert = require('assert');
const path = require('path');

const { createRequire, createRequireFromPath } = require('module');
const { createRequire } = require('module');

const p = path.resolve(__dirname, '..', 'fixtures', 'fake.js');
const u = new URL(`file://${p}`);

const req = createRequireFromPath(p);
assert.strictEqual(req('./baz'), 'perhaps I work');

const reqToo = createRequire(u);
assert.deepStrictEqual(reqToo('./experimental'), { ofLife: 42 });

Expand Down