A bare specifier names a module without giving a file path or URL. In Node.js, it is typically a package name; in a browser, an import map can map a bare specifier to a URL. Whether a runtime recognizes a specifier depends on that runtime. section 3.2.2 section 13.1.2
For Node.js package imports, resolution proceeds from the importing module’s location:
- Search upward for the closest node_modules directory containing the named package. section 3.2.2
- Check the package.json exports field for a matching entry point. If exports is absent, use an imported subpath relative to the package directory, or the main entry for a package-root import. section 3.2.2 section 13.1.2
- Package-manager Plug’n’Play modes can replace the node_modules search with resolution from a central cache. section 3.2.2
Listing 13.12 Importing from a package
import { lazyGetRandomTurtle } from "entry-point-example"; #A
import { getRandomTurtle } from "entry-point-example/ninjas/turtles"; #B
console.log(getRandomTurtle());
console.log(await lazyGetRandomTurtle());Compare a package-root import with an import naming a package subpath. section 13.1.2
