Open Ketlark opened 3 weeks ago
Hello, can you clarify which code snippet you used from the docs? And which page are you referring to?
Of course, it's this part : https://docs.medusajs.com/v2/resources/js-sdk#setup-js-sdk. I get rid of error but can't still used the SDK normally, even after tried multiple class import from it
Can you share your code block? Also, what type of project are you using it in?
import env from '#start/env'
import Medusa from '@medusajs/js-sdk'
export default class MedusaService {
private static instance: Medusa.Admin
private static MEDUSA_API_KEY = env.get('MEDUSA_API_KEY')
static getInstance() {
if (!MedusaService.instance) {
MedusaService.instance = new Medusa.default({
baseUrl: 'https://erp.mullo.fr',
apiKey: this.MEDUSA_API_KEY,
}).admin
}
return MedusaService.instance
}
}
A sample nodeJS backend project that use Medusa backend API
Can you please share the tsconfig of your project?
@thetutlage here is it
{
"extends": "@adonisjs/tsconfig/tsconfig.app.json",
"compilerOptions": {
"jsx": "react",
"rootDir": "./",
"outDir": "./build",
},
}
with base :
{
"compilerOptions": {
"target": "ESNext",
"module": "NodeNext",
"lib": ["ESNext"],
"noUnusedLocals": true,
"noUnusedParameters": true,
"isolatedModules": true,
"removeComments": true,
"esModuleInterop": true,
"strictNullChecks": true,
"allowSyntheticDefaultImports": true,
"forceConsistentCasingInFileNames": true,
"strictPropertyInitialization": true,
"experimentalDecorators": true,
"noImplicitAny": true,
"strictBindCallApply": true,
"strictFunctionTypes": true,
"noImplicitThis": true,
"skipLibCheck": true
},
"ts-node": {
"swc": true
}
}
Hello @Ketlark
I looked into the issue and it seems like our JS SDK is not compatible with the ESM implementation of Node.js and therefore it is not working at runtime and have type errors as well.
I will be working on it in the coming days and will let you know.
@thetutlage any news or blocking steps ? maybe i can help to fix it
Hello @Ketlark
Sorry for the late reply. We will discussing on fixing this issue this Monday internally and will keep you posted about it.
What Medusa version and documentation are you using?
v2
Preliminary Checks
Issue Summary
I want to use medusa JS SDK to perform call on backend server, but when i use the default sample code from documentation, the medusa object is not constructable:
How can this issue be resolved?
Issue can be solved by calling
new Medusa.default
Are you interested in working on this issue?