Skip to content

[BUG] ERR_PACKAGE_PATH_NOT_EXPORTED when importing SDK in CommonJS project #310

@maximelebastard

Description

@maximelebastard

Checks

  • I have updated to the lastest minor and patch version of Strands
  • I have checked the documentation and this is not expected behavior
  • I have searched ./issues and there are no duplicates of my issue

Strands Version

0.1.1

Node.js Version

22.13.0

Operating System

macOS 26.1

Installation Method

npm

Steps to Reproduce

  1. Create a new Node.js project without "type": "module" in package.json (CommonJS project)
  2. Install Strands SDK: npm install @strands-agents/sdk
  3. Create a TypeScript file that imports the SDK: import * as st from "@strands-agents/sdk"
  4. Try to run with tsx: npx tsx src/server.ts
  5. See error: ERR_PACKAGE_PATH_NOT_EXPORTED: No "exports" main defined

Minimal reproducible example:

package.json:

{
  "name": "test-strands",
  "version": "1.0.0",
  "dependencies": {
    "@strands-agents/sdk": "^0.1.1"
  },
  "devDependencies": {
    "tsx": "^4.21.0"
  }
}

main.ts

import * as st from "@strands-agents/sdk";

console.log("SDK imported successfully");

Run npx tsx src/test.ts

Expected Behavior

The SDK should be importable in both CommonJS and ES Module projects without requiring users to modify their project configuration to "type": "module"

Actual Behavior

Import fails with error:

[ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports" main defined in /path/to/node_modules/@strands-agents/sdk/package.json

Additional Context

The issue occurs because the SDK's package.json exports configuration only defines "import" paths but not "require" paths for CommonJS compatibility:

"exports": {
  ".": {
    "import": "./dist/src/index.js",
    "types": "./dist/src/index.d.ts"
  }
}

This makes the SDK incompatible with CommonJS projects, which is a common setup for many Node.js applications.

Possible Solution

Add CommonJS support to the exports configuration in package.json:

"exports": {
  ".": {
    "import": "./dist/src/index.js",
    "require": "./dist/src/index.js",
    "types": "./dist/src/index.d.ts"
  },
  "./openai": {
    "import": "./dist/src/models/openai.js",
    "require": "./dist/src/models/openai.js",
    "types": "./dist/src/models/openai.d.ts"
  }
  // ... etc
}

Related Issues

No response

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions