So the steps I followed:
npm init -y
npm i typescript
npx tsc --init
Follow the steps on the Developer console
node --version
with a potential upgrade of node:
nvm install node
nvm use node
Create the npmrc file for the repository
touch .npmrc
nano .npmrc
and drop the snippet from developer console
- Trigger the installation of the SDK
npm install @my-osdk-app/sdk@^0.1.0 @osdk/client@^2.0.9 @osdk/oauth@^1.0.0
- Generate a 2.0 SDK version + install the new version
@my-osdk-app/sdk@^0.2.0
- Add the hello world example code generated in Developer Console in my TS file.
- Add a few scripts
"scripts": {
"build": "tsc",
"start": "node dist/index.js",
"dev": "node --loader ts-node/esm src/index.ts"
},
so that one can run npm run build
or npm run dev
It seems that by default, a CommonJS package is created, which is not supported with OSDK.
Hence you need to change it for an ES Module.
The main trick for me has been to change the values in tsconfig.json
to:
{
"compilerOptions": {
"target": "ES2020",
"module": "ES2020",
"moduleResolution": "node",
"esModuleInterop": true,
"outDir": "./dist",
"rootDir": "./src",
"strict": true
},
"include": ["src/**/*"]
}
And to add "type": "module"
in package.json
:
{
"name": "tmp_osdk_app_test",
...
"scripts": {
"build": "tsc",
...
},
...
"type": "module"
}
Running npm run dev
"
(some warnings)
[
Object <Object <[Object: null prototype] {}>> {},
Object <Object <[Object: null prototype] {}>> {},
Object <Object <[Object: null prototype] {}>> {},
Object <Object <[Object: null prototype] {}>> {},
Object <Object <[Object: null prototype] {}>> {},
Object <Object <[Object: null prototype] {}>> {},
Object <Object <[Object: null prototype] {}>> {},
Object <Object <[Object: null prototype] {}>> {},
Object <Object <[Object: null prototype] {}>> {},
Object <Object <[Object: null prototype] {}>> {}
]