How to use OSDK in a simple Node Application?

I created an OSDK out of my ontology, and I want to do a simple hello-world

Steps followed:

  • npm init -y
  • npm i typescript
  • npx tsc --init

However, after copy pasting the example documentation in Developer Console, I get:
No "exports" main defined in [...]@osdk/client/package.json.

Is there something I’m doing wrong ? What configuration changes do I need to perform so that OSDK v2 is working for a simple hello world following the docs provided ?

I’m running into the exact same issue. Trying to upgrade from 1.1 and seeing the same error.

I am guessing this has to do with you tsconfig file. Try bootstrap the app based on the @osdk/create-app command in Dev console and compare your config.

Hi, I am experiencing the same error. My bootstrapped app works fine, but I need to integrate OSDK with an already existing typescript app. I have commonjs module in tsconfig. How should I change tsconfig to fix the error? An example code would also help. Maybe, import is different?

here is what I use:

{
  "compilerOptions": {
    "target": "ES2020",
    "useDefineForClassFields": true,
    "lib": ["ES2020", "DOM", "DOM.Iterable"],
    "module": "ESNext",
    "skipLibCheck": true,

    /* Bundler mode */
    "moduleResolution": "bundler",
    "allowImportingTsExtensions": true,
    "resolveJsonModule": true,
    "isolatedModules": true,
    "noEmit": true,
    "jsx": "react-jsx",

    /* Linting */
    "strict": true,
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "noFallthroughCasesInSwitch": true
  },
  "include": ["src"],
  "references": [{ "path": "./tsconfig.node.json" }]
}

and

{
  "compilerOptions": {
    "composite": true,
    "skipLibCheck": true,
    "module": "ESNext",
    "moduleResolution": "bundler",
    "allowSyntheticDefaultImports": true
  },
  "include": ["vite.config.ts"]
}

vite config is basic:

import react from "@vitejs/plugin-react";
import { defineConfig } from "vite";

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [react()],
  base:
    process.env.NODE_ENV === "development"
      ? process.env.DEV_SERVER_BASE_PATH
      : undefined,
  server: {
    port: Number(process.env.DEV_SERVER_PORT ?? 8080),
    host: process.env.DEV_SERVER_HOST,
  },
});
1 Like

Thanks for the example. Do you happen to have example code for OSDK with Express API Framework?

I think you asked this here.

Express is just a library for doing web-server stuff in nodejs so the basic config should be fine assuming you are using the latest ts version and basic config but we will get you an answer shortly.