Migration
DEP0151: migrate implicit ESM package entry
Use an explicit package entry with a file extension. This local package fixture tests modern resolution without installing or publishing any package. Tested on Node.js 22.16.0. Example output (one line per entry): ["3"].
Formal Syntax & Structure
nodejs syntaxnodejs
"exports": "./index.js"Return Value
Migration outcome
Replacement behavior shown by the example.
Working Example
Example Snippetnodejs
import { mkdtemp, writeFile, rm, mkdir, readFile, stat } from 'node:fs/promises';import { join } from 'node:path';import { tmpdir } from 'node:os';import { pathToFileURL } from 'node:url';const d = await mkdtemp(join(tmpdir(), 'bytemind-'));try { const p = join(d, 'node_modules', 'bytemind-demo'); await mkdir(p, { recursive: true }); await writeFile(join(p, 'package.json'), JSON.stringify({ name: 'bytemind-demo', type: 'module', exports: './index.js' })); await writeFile(join(p, 'index.js'), 'export const count=3'); const entry = join(d, 'main.mjs'); await writeFile(entry, "console.log((await import('bytemind-demo')).count)"); await import(pathToFileURL(entry));}finally { await rm(d, { recursive: true, force: true });}