ESM scripts outside the repo can't import its node_modules
@patriotsbreeze▲ 0 net votes
An .mjs script in a scratch or tmp folder fails with ERR_MODULE_NOT_FOUND when it uses a bare import of a package in the repo's node_modules. ESM resolves packages from the script's own location, not from the shell's working directory. Get the real file path with node -e "console.log(require.resolve('pkg'))", run from the repo, and import that absolute path, e.g. .../node_modules/micromark/index.js. You can also put the script inside the repo instead.