Skip to content

Conversation

@jsonbailey
Copy link
Contributor

@jsonbailey jsonbailey commented Nov 19, 2025

The dynamic loading of packages was failing in Next.js applications due to treeshaking. Even if you had the package installed, it would be excluded at runtime because it determined it was not needed. Instead of dynamically requiring a package, we explicitly import the package name which helps the process identify packages to include.


Note

Switches AI SDK and providers to dual ESM/CJS outputs with tsup and replaces dynamic require with explicit dynamic imports; updates build configs and tracking metadata.

  • Build/Module System:
    • Migrate @launchdarkly/server-sdk-ai and provider packages (server-ai-openai, server-ai-langchain, server-ai-vercel) to dual outputs (esm + cjs) via tsup; add exports map, files: ["dist"], and change type to module.
    • Update TS configs to ESM (module ESNext/ES2020), modern targets/libs, bundler/node resolution; extend eslint tsconfigs to include *.js.
  • Runtime Loading:
    • Replace dynamic require with explicit dynamic import(...) in api/providers/AIProviderFactory and add debug logs for provider creation.
  • API/Imports:
    • Change Mustache imports to default import in LDAIClientImpl and Judge.
    • Adjust LDLogger export to type alias from namespace import for CJS compatibility in src/index.ts.
  • Telemetry/Versioning:
    • Introduce src/sdkInfo.ts with aiSdkName/aiSdkVersion; use in LDAIConfigTrackerImpl and tests.
    • Update release-please-config.json to track src/sdkInfo.ts and example dependencies.
  • Tooling:
    • Add tsup.config.ts to SDK and provider packages.

Written by Cursor Bugbot for commit 46a645d. This will update automatically on new commits. Configure here.

@jsonbailey jsonbailey requested a review from a team as a code owner November 19, 2025 14:53
@github-actions
Copy link
Contributor

@launchdarkly/browser size report
This is the brotli compressed size of the ESM build.
Compressed size: 169118 bytes
Compressed size limit: 200000
Uncompressed size: 789399 bytes

@github-actions
Copy link
Contributor

@launchdarkly/js-sdk-common size report
This is the brotli compressed size of the ESM build.
Compressed size: 24988 bytes
Compressed size limit: 26000
Uncompressed size: 122411 bytes

@github-actions
Copy link
Contributor

@launchdarkly/js-client-sdk size report
This is the brotli compressed size of the ESM build.
Compressed size: 21981 bytes
Compressed size limit: 25000
Uncompressed size: 75580 bytes

@github-actions
Copy link
Contributor

@launchdarkly/js-client-sdk-common size report
This is the brotli compressed size of the ESM build.
Compressed size: 17636 bytes
Compressed size limit: 20000
Uncompressed size: 90259 bytes

@jsonbailey jsonbailey changed the title fix! Change to ES Modules to improve support of dynamic loading fix!: Change to ES Modules to improve support of dynamic loading Nov 19, 2025
"typescript": "5.1.6"
},
"peerDependencies": {
"@langchain/community": "^0.2.0 || ^0.3.0",
Copy link
Contributor Author

@jsonbailey jsonbailey Nov 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The community packages are nested (@langchain/community/chat_models/fireworks vs @langchain/aws) which causes runtime compile errors in Next.js when trying to load our langchain package. It's possible when we upgrade to langchain v1 this issue might go away but I was not able to get it to load without this additional dependency, even if it is not being used.

"moduleResolution": "node"
"moduleResolution": "bundler"
},
"include": ["src"],
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Inconsistent rootDir and include in tsconfig

The rootDir is set to "." while include is set to ["src"], creating a mismatch. This inconsistency can cause TypeScript to generate incorrect output directory structures or have issues with type checking and IDE support. The rootDir should be "./src" to match the include setting, similar to the other AI provider packages in this PR. The comment explaining the "." rootDir was removed because package.json is no longer imported, but the value wasn't updated accordingly.

Fix in Cursor Fix in Web

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants