Hi, I’m trying to build the authorization layer on...
# ask-a-descoper
m
Hi, I’m trying to build the authorization layer on our backend. I went through the docs and I’ve seen this code snapshot:
Copy code
import DescopeClient from '@descope/node-sdk';
try{
    //  baseUrl="<URL>" // When initializing the Descope clientyou can also configure the baseUrl ex: <https://auth.company.com>  - this is useful when you utilize CNAME within your Descope project.
    const descopeClient = DescopeClient({ projectId: '__ProjectID__' });
} catch (error) {
    // handle the error
    console.log("failed to initialize: " + error)
}
The problem is when I console.log the “DescopeClient” the result is undefined and I can’t initiate the DescopeClient({ projectId: ‘__ProjectID__’ }) object. I checked the node module and everything seems fine. Does anyone have a suggestion? do I use the sdk properly?
g
@few-holiday-24516 can you chime?
BTW few questions up front - you are using a vite configuration for the sever framework, right? Also - if you print the DescopeClient - what does it print?
m
Yes, we are using vite. it prints undefined
s
@famous-mouse-8066 you have some vite example to share ?
👍 1
f
We have examples on the Node repo but it’s working there @many-receptionist-47314 Could you possibly share your repository please? or consider creating a shared repository where the problem can be reproduced?
s
@many-receptionist-47314 did you happen to create an example repo ? You want us to setup a call to help you with this issue?
m
I’ve tried to run the Dockerfile in the es6 example, however, I’ve got the error: Error: Cannot find module ‘/usr/src/app/dist/index.js’ I’ve checked the docker file and it missed 2 commands to generate the dist folder, I’ve added them:
Copy code
RUN npm install
RUN npm run build
but now I’m getting a new error: Cannot find module ‘@descope/node-sdk’ I’ve also looked at the package.json:
Copy code
"@descope/node-sdk": "file:../..",
It would be great to setup a call, would like to solve it today and move forward 🙂
f
Can you run
npm run build
on the repo root level and try again?
@many-receptionist-47314 wanna hop on a Zoom call?
s
after review adding
esModuleInterop: true
in your
tsconfig.json|ts
file when using
import
syntax to load the sdk as ES module. we will also add this to our knowledge base, thank you!