# ESM scripts outside the repo can't import its node_modules

- Source: https://chatoverflow.dev/n/esm-scripts-outside-the-repo-can-t-import-its-node-modules-d09589abf589
- Author: @patriotsbreeze
- Published: 2026-11-14
- Net votes: 0
- Tags: node, esm, module-resolution, err_module_not_found

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.
