K
Kinde8mo ago
akl_isu

"@kinde-oss/kinde-node-express" doesn't support module js project

Hi I am trying to validate a user token send from my react frontend appliction to the node express server. My node express server is written module js and use named imports. But it seems like named imports doesn't supports by the "@kinde-oss/kinde-node-express" can someone guide me to fix this issue
[nodemon] app crashed - waiting for file changes before starting...
[nodemon] restarting due to changes...
[nodemon] starting `node index.js`
file:///D:/SLIIT/DBS/Assigment/Master-Learn-Online-Course-Platform-/backend/authentication-service/src/server.js:8
import { getUser, setupKinde } from "@kinde-oss/kinde-node-express";
^^^^^^^
SyntaxError: Named export 'getUser' not found. The requested module '@kinde-oss/kinde-node-express' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

import pkg from '@kinde-oss/kinde-node-express';
const { getUser, setupKinde } = pkg;

at ModuleJob._instantiate (node:internal/modules/esm/module_job:124:21)
at async ModuleJob.run (node:internal/modules/esm/module_job:190:5)

Node.js v18.18.0
[nodemon] app crashed - waiting for file changes before starting...
[nodemon] restarting due to changes...
[nodemon] starting `node index.js`
file:///D:/SLIIT/DBS/Assigment/Master-Learn-Online-Course-Platform-/backend/authentication-service/src/server.js:8
import { getUser, setupKinde } from "@kinde-oss/kinde-node-express";
^^^^^^^
SyntaxError: Named export 'getUser' not found. The requested module '@kinde-oss/kinde-node-express' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

import pkg from '@kinde-oss/kinde-node-express';
const { getUser, setupKinde } = pkg;

at ModuleJob._instantiate (node:internal/modules/esm/module_job:124:21)
at async ModuleJob.run (node:internal/modules/esm/module_job:190:5)

Node.js v18.18.0
import express from "express";
import cookieParser from "cookie-parser";
import { PORT } from "./config/config.js";
import errorHandler from "./middleware/errorhandler.js";
import authentication from "./route/auth.router.js";
import cors from "cors";
import morgan from "morgan";
import { getUser, setupKinde } from "@kinde-oss/kinde-node-express";
//express
const app = express();

const config = {
clientId: "",
domain: "",
redirectUri: "",
logoutUri: "",
};

setupKinde(config, app);

//middlewares
app.use(
cors({
origin: "http://localhost:5173",
credentials: true,
})
);
import express from "express";
import cookieParser from "cookie-parser";
import { PORT } from "./config/config.js";
import errorHandler from "./middleware/errorhandler.js";
import authentication from "./route/auth.router.js";
import cors from "cors";
import morgan from "morgan";
import { getUser, setupKinde } from "@kinde-oss/kinde-node-express";
//express
const app = express();

const config = {
clientId: "",
domain: "",
redirectUri: "",
logoutUri: "",
};

setupKinde(config, app);

//middlewares
app.use(
cors({
origin: "http://localhost:5173",
credentials: true,
})
);
{
.....
"type": "module",
"scripts": {
"dev": "nodemon index.js",
}
"dependencies": {
....
"@kinde-oss/kinde-node-express": "^1.4.0",
....
}
}
{
.....
"type": "module",
"scripts": {
"dev": "nodemon index.js",
}
"dependencies": {
....
"@kinde-oss/kinde-node-express": "^1.4.0",
....
}
}
No description
No description
8 Replies
Oli - Kinde
Oli - Kinde8mo ago
Hi @akl_isu, It looks like you're encountering an issue with named imports due to the @kinde-oss/kinde-node-express package being a CommonJS module. In Node.js, especially with ES modules (type: "module" in your package.json), you might face compatibility issues when trying to use named imports directly from CommonJS modules. To resolve this issue, you should import the entire module as a default import and then destructure the needed functions from it. Here's how you can modify your import statement:
import kindeExpress from "@kinde-oss/kinde-node-express";
const { getUser, setupKinde } = kindeExpress;
import kindeExpress from "@kinde-oss/kinde-node-express";
const { getUser, setupKinde } = kindeExpress;
This change should allow you to correctly import and use the getUser and setupKinde functions from the @kinde-oss/kinde-node-express package in your Node.js application using ES modules. Please let me know if you are still experiencing issues.
akl_isu
akl_isuOP8mo ago
Hi @Oli - Kinde I am still facing to same issues with the default import also
akl_isu
akl_isuOP8mo ago
No description
Oli - Kinde
Oli - Kinde8mo ago
Hey @akl_isu, Apologies, this message slipped beneath the cracks in my Discord. Are you still experiencing this issue?
akl_isu
akl_isuOP8mo ago
Yes actually I tried kindle for academic project, I found a another implementation for the authentication. However I am still facing to issue
Oli - Kinde
Oli - Kinde8mo ago
Hey @akl_isu, This is good context to know. Our Express SDK takes a little longer than usual to update. I have passed this onto my team but I cannot provide any ETAs on when this issue will be fixed. Apologies.
akl_isu
akl_isuOP8mo ago
No worries, anyway I really liked the React Implementation it's so convenient
Oli - Kinde
Oli - Kinde8mo ago
Thanks for the feedback
Want results from more Discord servers?
Add your server