question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports" main

See original GitHub issue

Hello, im having an issue importing this module when running even the simplest example. After upgrading this package from 2.7.x to latest, I’m getting this error when attempting to import



Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports" main defined in /Users/x/node_modules/fastify-openapi-glue/package.json
    at new NodeError (node:internal/errors:372:5)
    at throwExportsNotFound (node:internal/modules/esm/resolve:472:9)
    at packageExportsResolve (node:internal/modules/esm/resolve:693:7)
    at resolveExports (node:internal/modules/cjs/loader:482:36)
    at Function.Module._findPath (node:internal/modules/cjs/loader:522:31)
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:919:27)
    at Function.Module._load (node:internal/modules/cjs/loader:778:27)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (/Users/x/dist/index.js:18:43) {
  code: 'ERR_PACKAGE_PATH_NOT_EXPORTED'
}

Is it something with the new esm update? I’m using typescript 4.7.4 and im using node 16.

index.ts

import fastify from "fastify";
import cors from "@fastify/cors";
import fastifyOpenapiGlue from "fastify-openapi-glue";
// const fastifyOpenapiGlue = require("fastify-openapi-glue");

const app = fastify();

app.register(cors);

app.register(fastifyOpenapiGlue);

console.log("fastify", fastify);

tsconfig.json

{
  "compilerOptions": {
    "target": "ES2022" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
    "module": "CommonJS" /* Specify what module code is generated. */,
    "esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */,
    "forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */,
    "strict": true /* Enable all strict type-checking options. */,
    "skipLibCheck": true /* Skip type checking all .d.ts files. */
  }
}

start script:

tsc && node index.js

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:12 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
seriousmecommented, Jul 12, 2022

Good to read you got a solution !

I presume more people will have issues with this subject as many packages are migrating to ESM. Lets hope the Typescript team documents this a little better 😉

Kind regards, Hans

1reaction
jonasgroendahlcommented, Jul 12, 2022

Thanks for investigating this, I really had many issues working with ESM when it comes to TypeScript

I think I got it working using in package.json:

  "type": "module"

tsconfig.json


{
"compilerOptions": {
  "target": "ES2022" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
  "module": "Es2020" /* Specify what module code is generated. */,
  "esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */,
  "forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */,
  "strict": true /* Enable all strict type-checking options. */,
  "skipLibCheck": true /* Skip type checking all .d.ts files. */,
  "moduleResolution": "Node",
  "outDir": "dist",
  "rootDir": "src"
}
}

.js file become this: 😃

import fastify from "fastify";
import cors from "@fastify/cors";
import { fastifyOpenapiGlue } from "fastify-openapi-glue";
// const fastifyOpenapiGlue = require("fastify-openapi-glue");
const app = fastify();
app.register(cors);
app.register(fastifyOpenapiGlue);
console.log("fastify", fastify);
Read more comments on GitHub >

github_iconTop Results From Across the Web

No "exports" main resolved in /app/node_modules/@babel ...
node 13.14.0, node 12.18.4, 12.19.0, 12.19.1 show the error : ERR_PACKAGE_PATH_NOT_EXPORTED; With node 12.20.0, node 14.17.4, the error is ...
Read more >
Error [ERR_PACKAGE_PATH_NOT_EXPORTED] #142 - GitHub
Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports" main defined in .../node_modules/jose/package.json means you're doing require/import of just ...
Read more >
Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No 'exports'
Run the npm update command to solve the "Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No 'exports'" and then run npm audit fix --force if necessary.
Read more >
No "exports" main defined - Laracasts
Hello , After cloning my project I got the error bellow when I npm run watch (I deleted ... Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports"...
Read more >
No "exports" main resolved in@babel/helper-compilation ...
Coding example for the question Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports" main resolved in@babel/helper-compilation-targets/package.json-babel.js.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found