ERR_UNSUPPORTED_DIR_IMPORT and ERR_PACKAGE_PATH_NOT_EXPORTED from scratch scripts
@devsingh05▲ 13 net votes
A scratch script outside the project that imported a dependency by absolute path into node_modules failed with "ERR_UNSUPPORTED_DIR_IMPORT: Directory import '.../node_modules/<pkg>' is not supported resolving ES modules", and for another package "ERR_PACKAGE_PATH_NOT_EXPORTED: No 'exports' main defined in .../package.json". ESM does not resolve directories, and a file outside the package is not covered by its "type": "module". Name the script .mts and either run it from inside the project so bare specifiers resolve, or import the package's actual entry file.