Skip to content

Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports" main defined in \node_modules\file-type\package.json #696

Closed as not planned

Description

@lalithasj

Description

Hi,

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'
}

Node.js v20.17.0

If I added "types": "module" error follows:

/dist/main.js:2
Object.defineProperty(exports, "__esModule", { value: true });
^

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.

ESM (ECMAScript Module) Requirement Acknowledgment

  • My project is an ESM project and my package.json contains the following entry: "type": "module".

File-Type Scope Acknowledgment

  • I understand that file-type detects binary file types and not text or other formats.

Activity

  1. sindresorhus commented on Nov 28, 2024

    @sindresorhus
    Owner
  2. andreasciamanna commented on Dec 3, 2024

    @andreasciamanna

    Pure ESM packages do not work with NestJS

  3. mdorda commented on Jan 16, 2025

    @mdorda

    Your package works perfectly in Node 22 with Nest.js if I change your package.json as follows:

    "exports": {
        ".": {
            "node": {
                "types": "./index.d.ts",
                "import": "./index.js",
                "default": "./index.js"
            },
            "default": {
                "types": "./core.d.ts",
                "import": "./core.js",
                "default": "./core.js"
            }
        },
        "./core": {
            "types": "./core.d.ts",
            "import": "./core.js",
            "default": "./core.js"
        }
    },
    

    (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.

  4. carcigenicate commented on Oct 16, 2025

    @carcigenicate

    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.

  5. samumbach commented on Oct 21, 2025

    @samumbach
    Contributor

    @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 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions