-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports" main #382
Comments
Hi, thanks for asking ! The challenge is indeed caused by migrating to ESM.
See: https://www.typescriptlang.org/docs/handbook/esm-node.html
import { fastifyOpenapiGlue } from "fastify-openapi-glue"; Hope this helps, please let me know if any (or all ;-)) of these options work ! Kind regards, |
Hi Hans, thanks for replying! I changed to
Now i'm getting a red underline under the import, saying: Cannot find module 'fastify-openapi-glue' or its corresponding type declarations.ts(2307) If I ignore the ts error and run it, it will yield same error as before :( |
Ok, I tried it myself but somehow Typescript keeps generating CommonJS "use strict";
exports.__esModule = true;
var fastify_1 = require("fastify");
var fastify_openapi_glue_1 = require("fastify-openapi-glue");
// const fastifyOpenapiGlue = require("fastify-openapi-glue");
var app = (0, fastify_1["default"])();
app.register(fastify_openapi_glue_1["default"]);
console.log("fastify", fastify_1["default"]); |
Ok, I think I got it working. Its seems to be a quirck in Typescript :-( I followed the instructions at: https://2ality.com/2021/06/typescript-esm-nodejs.html and got after compilation in index.js: import fastify from "fastify";
import fastifyOpenapiGlue from "fastify-openapi-glue";
// const fastifyOpenapiGlue = require("fastify-openapi-glue");
const app = fastify();
app.register(fastifyOpenapiGlue);
console.log("fastify", fastify); However this only happens if tsconfig contains: "rootDir": "ts",
"outDir": "dist", If not, it will fall back to commonJS again !??! btw: Package.json must be set to Hope this helps ! Kind regards, |
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
.js file become this: :)
|
Good to read you got a solution ! I presume more people will have issues with this subject as many packages are migrating to ESM. Kind regards, |
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days' |
Hello, does anyone here using tsc-esm? The issue still persists when using tsc-esm |
Hi, I haven't used tsc-esm however the README.md mentions:
https://www.npmjs.com/package/@digitak/tsc-esm I hope that answers your question ;-) Kind regards, |
Thank you, appreciate your answer! |
Good to read you got it working ! |
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days' |
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
Is it something with the new
esm
update? I'm using typescript 4.7.4 and im using node 16.index.ts
tsconfig.json
start script:
The text was updated successfully, but these errors were encountered: