module.createRequire(filename)
import { createRequire } from 'module';
const require = createRequire(import.meta.url);
// sibling-module.js 是 CommonJS 模块。
const siblingModule = require('./sibling-module');
filename
<string> | <URL> Filename to be used to construct the require function. Must be a file URL object, file URL string, or absolute path string.- Returns: <require> Require function
import { createRequire } from 'module';
const require = createRequire(import.meta.url);
// sibling-module.js is a CommonJS module.
const siblingModule = require('./sibling-module');