Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(core): externalize @cfworker/json-schema dependency #7298

Merged
merged 3 commits into from
Dec 9, 2024

Conversation

jdanyow
Copy link
Contributor

@jdanyow jdanyow commented Nov 30, 2024

Back in #1878, the dependency was inlined to avoid portability issues, which have since been resolved.

Copy link

vercel bot commented Nov 30, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
langchainjs-docs ✅ Ready (Inspect) Visit Preview Dec 6, 2024 4:01am
1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
langchainjs-api-refs ⬜️ Ignored (Inspect) Dec 6, 2024 4:01am

@dosubot dosubot bot added size:XXL This PR changes 1000+ lines, ignoring generated files. auto:nit Small modifications/deletions, fixes, deps or improvements to existing code or docs labels Nov 30, 2024
@jacoblee93
Copy link
Collaborator

Thank you and thank you for your awesome work!

@jacoblee93
Copy link
Collaborator

Ah seems it's still failing our export tests:

/app/libs/langchain-core/dist/output_parsers/transform.cjs:4
const json_schema_1 = require("@cfworker/json-schema");
                      ^

Error [ERR_REQUIRE_ESM]: require() of ES Module /app/node_modules/@cfworker/json-schema/dist/cjs/index.js from /app/libs/langchain-core/dist/output_parsers/transform.cjs not supported.
index.js is treated as an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which declares all .js files in that package scope as ES modules.
Instead either rename index.js to end in .cjs, change the requiring code to use dynamic import() which is available in all CommonJS modules, or change "type": "module" to "type": "commonjs" in /app/node_modules/@cfworker/json-schema/package.json to treat all .js files as CommonJS (using .mjs for all ES modules instead).

    at Object.<anonymous> (/app/libs/langchain-core/dist/output_parsers/transform.cjs:4:23)
    at Object.<anonymous> (/app/libs/langchain-core/dist/output_parsers/bytes.cjs:4:24)
    at Object.<anonymous> (/app/libs/langchain-core/dist/output_parsers/index.cjs:18:14)
    at Object.<anonymous> (/app/libs/langchain-core/output_parsers.cjs:1:18)
    at Object.<anonymous> (/app/libs/langchain-openai/dist/chat_models.cjs:11:26)
    at Object.<anonymous> (/app/libs/langchain-openai/dist/index.cjs:21:14)
    at Object.<anonymous> (/app/libs/langchain-openai/index.cjs:1:18)
    at Object.<anonymous> (/app/src/require.cjs:2:20) {
  code: 'ERR_REQUIRE_ESM'
}

@jdanyow
Copy link
Contributor Author

jdanyow commented Dec 5, 2024

hmm- my bad- I'll look into it and post back with an update soon. We had just added a require export to the package so I thought it was finally resolved.
https://github.com/cfworker/cfworker/blob/main/packages/json-schema/package.json#L28

@dosubot dosubot bot added size:XL This PR changes 500-999 lines, ignoring generated files. and removed size:XXL This PR changes 1000+ lines, ignoring generated files. labels Dec 5, 2024
@dosubot dosubot bot added size:XXL This PR changes 1000+ lines, ignoring generated files. and removed size:XL This PR changes 500-999 lines, ignoring generated files. labels Dec 5, 2024
@jacoblee93
Copy link
Collaborator

If helpful - after a lot of trial and error we ended up on this:

https://github.com/langchain-ai/langchainjs/blob/main/langchain-core/package.json#L298

I do not know we need all of it since we're using it internally (our users won't need the CF worker types, for example)

@jdanyow
Copy link
Contributor Author

jdanyow commented Dec 6, 2024

I ended up switching my build to https://www.npmjs.com/package/tshy, which simplified things, and seems to produce a solid dual ESM/CommonJS distributable.

The package no longer has any dependencies, other than devDependencies, hopefully that eliminates the cloudflare worker types related issues.

@jacoblee93
Copy link
Collaborator

Giving it another shot now thanks!

@jacoblee93
Copy link
Collaborator

Good enough for our CI! Thank you so much.

@jacoblee93 jacoblee93 added lgtm PRs that are ready to be merged as-is and removed hold On hold labels Dec 9, 2024
@jacoblee93 jacoblee93 merged commit 16ffbea into langchain-ai:main Dec 9, 2024
36 checks passed
syntaxsec pushed a commit to aks-456/langchainjs that referenced this pull request Dec 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto:nit Small modifications/deletions, fixes, deps or improvements to existing code or docs lgtm PRs that are ready to be merged as-is size:XXL This PR changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants