Incorrect exports in @opencode-ai/sdk package.json causing import failures #8082

Closed
opened 2026-02-16 18:09:07 -05:00 by yindo · 7 comments
Owner

Originally created by @MBanucu on GitHub (Jan 30, 2026).

Originally assigned to: @thdxr on GitHub.

Issue

The @opencode-ai/sdk package has a configuration issue in its package.json that causes import failures in consumer packages.

Problem

  • Exports point to ./src/*.ts files (e.g., "./client": "./src/client.ts")
  • files only includes "dist" - the src/ directory is not included in published packages
  • publishConfig.directory: "dist" - npm publishes the dist/ directory as the package root

This means:

  1. During development: src/ exists, exports work
  2. When published: only dist/ is included, but exports still point to non-existent src/ paths
  3. Consumers get "Cannot find module" errors because exported paths don't exist

Impact

  • Breaks imports like import { OpencodeClient } from '@opencode-ai/sdk'
  • Forces consumers to use workarounds like direct dist/ paths

Expected Fix

Update exports to point to dist/ files:

"exports": {
  ".": "./dist/index.js",
  "./client": "./dist/client.js",
  "./server": "./dist/server.js",
  "./v2": "./dist/v2/index.js",
  "./v2/client": "./dist/v2/client.js",
  "./v2/server": "./dist/v2/server.js"
}

Reproduction

Install @opencode-ai/sdk and try importing from it - the module resolution fails.

Found while fixing npm pack integration test in opencode-pty.

Originally created by @MBanucu on GitHub (Jan 30, 2026). Originally assigned to: @thdxr on GitHub. ## Issue The `@opencode-ai/sdk` package has a configuration issue in its `package.json` that causes import failures in consumer packages. ### Problem - **Exports** point to `./src/*.ts` files (e.g., `"./client": "./src/client.ts"`) - **files** only includes `"dist"` - the `src/` directory is not included in published packages - **publishConfig.directory: "dist"** - npm publishes the `dist/` directory as the package root This means: 1. During development: `src/` exists, exports work 2. When published: only `dist/` is included, but exports still point to non-existent `src/` paths 3. Consumers get "Cannot find module" errors because exported paths don't exist ### Impact - Breaks imports like `import { OpencodeClient } from '@opencode-ai/sdk'` - Forces consumers to use workarounds like direct `dist/` paths ### Expected Fix Update exports to point to `dist/` files: ```json "exports": { ".": "./dist/index.js", "./client": "./dist/client.js", "./server": "./dist/server.js", "./v2": "./dist/v2/index.js", "./v2/client": "./dist/v2/client.js", "./v2/server": "./dist/v2/server.js" } ``` ### Reproduction Install `@opencode-ai/sdk` and try importing from it - the module resolution fails. Found while fixing npm pack integration test in opencode-pty.
yindo closed this issue 2026-02-16 18:09:07 -05:00
Author
Owner

@github-actions[bot] commented on GitHub (Jan 30, 2026):

This issue might be a duplicate of existing issues. Please check:

  • #8006: @opencode-ai/plugin - ESM imports missing .js extension breaks plugin loading (similar exports/dist configuration issue)

Feel free to ignore if none of these address your specific case.

@github-actions[bot] commented on GitHub (Jan 30, 2026): This issue might be a duplicate of existing issues. Please check: - #8006: @opencode-ai/plugin - ESM imports missing .js extension breaks plugin loading (similar exports/dist configuration issue) Feel free to ignore if none of these address your specific case.
Author
Owner

@MBanucu commented on GitHub (Jan 30, 2026):

Here's the current package.json from @opencode-ai/sdk v1.1.46 that exhibits the issue:

{
  "$schema": "https://json.schemastore.org/package.json",
  "name": "@opencode-ai/sdk",
  "version": "1.1.46",
  "type": "module",
  "license": "MIT",
  "scripts": {
    "typecheck": "tsgo --noEmit",
    "build": "./script/build.ts"
  },
  "exports": {
    ".": "./src/index.ts",
    "./client": "./src/client.ts",
    "./server": "./src/server.ts",
    "./v2": "./src/v2/index.ts",
    "./v2/client": "./src/v2/client.ts",
    "./v2/server": "./src/v2/server.ts"
  },
  "files": [
    "dist"
  ],
  "devDependencies": {
    "@hey-api/openapi-ts": "0.90.10",
    "@tsconfig/node22": "22.0.2",
    "@types/node": "22.13.9",
    "typescript": "5.8.2",
    "@typescript/native-preview": "7.0.0-dev.20251207.1"
  },
  "dependencies": {},
  "publishConfig": {
    "directory": "dist"
  }
}
@MBanucu commented on GitHub (Jan 30, 2026): Here's the current `package.json` from `@opencode-ai/sdk` v1.1.46 that exhibits the issue: ```json { "$schema": "https://json.schemastore.org/package.json", "name": "@opencode-ai/sdk", "version": "1.1.46", "type": "module", "license": "MIT", "scripts": { "typecheck": "tsgo --noEmit", "build": "./script/build.ts" }, "exports": { ".": "./src/index.ts", "./client": "./src/client.ts", "./server": "./src/server.ts", "./v2": "./src/v2/index.ts", "./v2/client": "./src/v2/client.ts", "./v2/server": "./src/v2/server.ts" }, "files": [ "dist" ], "devDependencies": { "@hey-api/openapi-ts": "0.90.10", "@tsconfig/node22": "22.0.2", "@types/node": "22.13.9", "typescript": "5.8.2", "@typescript/native-preview": "7.0.0-dev.20251207.1" }, "dependencies": {}, "publishConfig": { "directory": "dist" } } ```
Author
Owner

@MBanucu commented on GitHub (Jan 30, 2026):

Update: After investigating the @opencode-ai/sdk dist files, they do have proper .js extensions in all imports/exports (unlike the plugin package). The issue is solely the package.json exports pointing to non-existent src/ paths instead of the published dist/ files.

This is a different issue from #8006, which affects @opencode-ai/plugin and involves both export paths AND missing .js extensions in compiled code.

For the SDK, the fix only requires updating the exports in package.json to point to dist/ files.

@MBanucu commented on GitHub (Jan 30, 2026): Update: After investigating the `@opencode-ai/sdk` dist files, they **do have proper `.js` extensions** in all imports/exports (unlike the plugin package). The issue is solely the `package.json` exports pointing to non-existent `src/` paths instead of the published `dist/` files. This is a **different issue** from #8006, which affects `@opencode-ai/plugin` and involves both export paths AND missing `.js` extensions in compiled code. For the SDK, the fix only requires updating the exports in `package.json` to point to `dist/` files.
Author
Owner

@MBanucu commented on GitHub (Jan 30, 2026):

Regression Analysis

After comparing different versions of @opencode-ai/sdk, this appears to be a regression introduced in v1.1.46:

Working Version (v1.1.34)

  • Exports correctly point to dist/ files
  • Uses proper object format: "./client": { "import": "./dist/client.js", "types": "./dist/client.d.ts" }
  • Works correctly for published packages

Broken Version (v1.1.46)

  • Exports incorrectly point to src/ files
  • Uses string format: "./client": "./src/client.ts"
  • Fails because src/ is not included in published packages (files: ["dist"])

Impact

This regression breaks all consumers trying to import from @opencode-ai/sdk after the v1.1.46 update. The package maintainers likely updated the exports during development but didn't account for the publish process that moves dist/ to the package root.

Urgency: This affects all users of the SDK v1.1.46+. A hotfix reverting the exports to point to dist/ is needed.

@MBanucu commented on GitHub (Jan 30, 2026): ## Regression Analysis After comparing different versions of `@opencode-ai/sdk`, this appears to be a **regression introduced in v1.1.46**: ### Working Version (v1.1.34) - **Exports correctly point to `dist/` files** - Uses proper object format: `"./client": { "import": "./dist/client.js", "types": "./dist/client.d.ts" }` - Works correctly for published packages ### Broken Version (v1.1.46) - **Exports incorrectly point to `src/` files** - Uses string format: `"./client": "./src/client.ts"` - Fails because `src/` is not included in published packages (`files: ["dist"]`) ### Impact This regression breaks all consumers trying to import from `@opencode-ai/sdk` after the v1.1.46 update. The package maintainers likely updated the exports during development but didn't account for the publish process that moves `dist/` to the package root. **Urgency**: This affects all users of the SDK v1.1.46+. A hotfix reverting the exports to point to `dist/` is needed.
Author
Owner

@MBanucu commented on GitHub (Jan 30, 2026):

Working Package.json (v1.1.34)

For reference, here's the package.json from the working version v1.1.34:

{
  "$schema": "https://json.schemastore.org/package.json",
  "name": "@opencode-ai/sdk",
  "version": "1.1.34",
  "type": "module",
  "license": "MIT",
  "scripts": {
    "typecheck": "tsgo --noEmit",
    "build": "./script/build.ts"
  },
  "exports": {
    ".": {
      "import": "./dist/index.js",
      "types": "./dist/index.d.ts"
    },
    "./client": {
      "import": "./dist/client.js",
      "types": "./dist/client.d.ts"
    },
    "./server": {
      "import": "./dist/server.js",
      "types": "./dist/server.d.ts"
    },
    "./v2": {
      "import": "./dist/v2/index.js",
      "types": "./dist/v2/index.d.ts"
    },
    "./v2/client": {
      "import": "./dist/v2/client.js",
      "types": "./dist/v2/client.d.ts"
    },
    "./v2/server": {
      "import": "./dist/v2/server.js",
      "types": "./dist/v2/server.d.ts"
    }
  },
  "files": [
    "dist"
  ],
  "devDependencies": {
    "@hey-api/openapi-ts": "0.90.4",
    "@tsconfig/node22": "22.0.2",
    "@types/node": "22.13.9",
    "typescript": "5.8.2",
    "@typescript/native-preview": "7.0.0-dev.20251207.1"
  },
  "dependencies": {},
  "publishConfig": {
    "directory": "dist"
  }
}

This shows the correct export format that should be restored in v1.1.46+.

@MBanucu commented on GitHub (Jan 30, 2026): ## Working Package.json (v1.1.34) For reference, here's the `package.json` from the working version v1.1.34: ```json { "$schema": "https://json.schemastore.org/package.json", "name": "@opencode-ai/sdk", "version": "1.1.34", "type": "module", "license": "MIT", "scripts": { "typecheck": "tsgo --noEmit", "build": "./script/build.ts" }, "exports": { ".": { "import": "./dist/index.js", "types": "./dist/index.d.ts" }, "./client": { "import": "./dist/client.js", "types": "./dist/client.d.ts" }, "./server": { "import": "./dist/server.js", "types": "./dist/server.d.ts" }, "./v2": { "import": "./dist/v2/index.js", "types": "./dist/v2/index.d.ts" }, "./v2/client": { "import": "./dist/v2/client.js", "types": "./dist/v2/client.d.ts" }, "./v2/server": { "import": "./dist/v2/server.js", "types": "./dist/v2/server.d.ts" } }, "files": [ "dist" ], "devDependencies": { "@hey-api/openapi-ts": "0.90.4", "@tsconfig/node22": "22.0.2", "@types/node": "22.13.9", "typescript": "5.8.2", "@typescript/native-preview": "7.0.0-dev.20251207.1" }, "dependencies": {}, "publishConfig": { "directory": "dist" } } ``` This shows the correct export format that should be restored in v1.1.46+.
Author
Owner

@thdxr commented on GitHub (Jan 30, 2026):

should be fixed in 1.1.47?

@thdxr commented on GitHub (Jan 30, 2026): should be fixed in 1.1.47?
Author
Owner

@MBanucu commented on GitHub (Feb 1, 2026):

Good.

Tested, fixed.

@MBanucu commented on GitHub (Feb 1, 2026): Good. Tested, fixed.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#8082