You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports" main defined in \node_modules\file-type\package.json #696
I got the following error without "types": "module":
node:internal/modules/cjs/loader:641
throw e;
^
Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports" main defined in \node_modules\file-type\package.json
at exportsNotFound (node:internal/modules/esm/resolve:304:10)
at packageExportsResolve (node:internal/modules/esm/resolve:594:13)
at resolveExports (node:internal/modules/cjs/loader:634:36)
at Module._findPath (node:internal/modules/cjs/loader:724:31)
at Module._resolveFilename (node:internal/modules/cjs/loader:1211:27)
at Module._load (node:internal/modules/cjs/loader:1051:27)
at Module.require (node:internal/modules/cjs/loader:1311:19)
at require (node:internal/modules/helpers:179:18)
at Object. (E:\WebDevelopment\AngularWithNestJS\linkedin-clone\api\src\auth\helpers\image-storage.ts:5:1)
at Module._compile (node:internal/modules/cjs/loader:1469:14) {
code: 'ERR_PACKAGE_PATH_NOT_EXPORTED'
}
ReferenceError: exports is not defined in ES module scope
This file is being treated as an ES module because it has a '.js' file extension and '\package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.
at file: /dist/main.js:2:23
at ModuleJob.run (node:internal/modules/esm/module_job:234:25)
at async ModuleLoader.import (node:internal/modules/esm/loader:473:24)
at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:123:5)
Node.js v20.17.0
Appreciate any suggestions.
Existing Issue Check
I have searched the existing issues and could not find any related to my problem.
(added default to all properties)
Then it works thanks to require(ESM) feature in Node. Unfortunately, without editing the package.json, it does not work and fails on:
Error: No "exports" main defined in /node_modules/file-type/package.json
Any chance to consider changing package.json? I fully understand why to use ESM, but Nest.js does not support it, unfortunately. I am not a fan of CJS, but have no choice.
Bizarrely, this doesn't cause errors in Node 20.19.5. I have no idea how that works, but I get errors on versions other than 20.19.5 when using CommonJS, but not 20.19.5.
@carcigenicate Yes, I just observed this issue with Node.js 20.18.3 but not 20.19.0 -- it looks like this was resolved in 20.19.0, perhaps with the backport of nodejs/node#51977 .
Activity
sindresorhus commentedon Nov 28, 2024
https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
andreasciamanna commentedon Dec 3, 2024
Pure ESM packages do not work with NestJS
mdorda commentedon Jan 16, 2025
Your package works perfectly in Node 22 with Nest.js if I change your package.json as follows:
(added default to all properties)
Then it works thanks to require(ESM) feature in Node. Unfortunately, without editing the package.json, it does not work and fails on:
Any chance to consider changing package.json? I fully understand why to use ESM, but Nest.js does not support it, unfortunately. I am not a fan of CJS, but have no choice.
fix: Fix require(ESM) for Node v22
fix: Fix require(ESM) for Node v22
carcigenicate commentedon Oct 16, 2025
Bizarrely, this doesn't cause errors in Node 20.19.5. I have no idea how that works, but I get errors on versions other than 20.19.5 when using CommonJS, but not 20.19.5.
samumbach commentedon Oct 21, 2025
@carcigenicate Yes, I just observed this issue with Node.js 20.18.3 but not 20.19.0 -- it looks like this was resolved in 20.19.0, perhaps with the backport of nodejs/node#51977 .