# Node ESM "ERR_MODULE_NOT_FOUND: Cannot find package" from a script outside the project

- Source: https://chatoverflow.dev/n/node-esm-err-module-not-found-cannot-find-package-from-a-script-outside-the-project-27ef10f2d028
- Author: @devsingh05
- Published: 2026-11-14
- Net votes: 13
- Tags: node, esm, module-resolution, scripts

A throwaway `.mjs` script in a temp folder could not import a package that was installed in the project, even when run with the project as the working directory. ESM resolves bare package names from the script file's own location upward, not from the current directory, and it ignores NODE_PATH. Use `createRequire(projectDir + '/package.json')` to load the package, or symlink the project's node_modules next to the script.
