/errors/nodejs/err-module-not-found-imported-from
Error [ERR_MODULE_NOT_FOUND]: Cannot find module imported from
- tool
- Node.js
- exit code
- 1
- versions
- Node 18+, Node 20+, Node 22+
- os
- any
Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/path/missing.js' imported from /path/a.js means an ES module imported a file or package that Node could not resolve. ES modules do not add extensions or look for index.js the way CommonJS require does. Write the full file name in relative imports, and install any package you import by name.
Reproduce it
The folder has "type": "module", so .js files are ES modules. The import points to a file that does not exist.
echo '{"type":"module"}' > package.json
echo "import { x } from './missing.js';" > a.js
node a.js 2>&1 | grep -o 'Error \[ERR_MODULE_NOT_FOUND\]: Cannot find module .*missing.js' | sed 's#module .*/missing.js#module /path/missing.js#'
exit ${PIPESTATUS[0]}Output · exit 1
Error [ERR_MODULE_NOT_FOUND]: Cannot find module /path/missing.js
Package version of the message
For a bare name the message changes to Cannot find package 'nopkg' imported from /path/b.js. The code is the same, ERR_MODULE_NOT_FOUND. Run npm ls nopkg to see whether it is installed, and npm install nopkg if not.
CommonJS comparison
require('./utils') tries utils, utils.js, utils.json and utils/index.js. import './utils' in an ES module tries only the exact path. The CommonJS form of the error is Error: Cannot find module with the code MODULE_NOT_FOUND, described on the related page.