-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
fix: use workaround for dynamic import #956
fix: use workaround for dynamic import #956
Conversation
Reviewer ChecklistPlease leverage this checklist to ensure your code review is thorough before approving Testing, Bugs, Errors, Logs, Documentation
System Compatibility
Quality
|
@perzeuss this is great! great work figuring this out. I wanted to square up this comment from @shuding (on the vercel nextjs team afaik) #824 (comment) --> would this be an alternate way of solving the same issue? |
No, the comment you're referring to is about the lack of an ECMAScript Modules (ESM) build. As I mentioned in issue #953, Chroma isn't currently optimized for browser environments. The suggestion in the comment is to include an ESM build target, which would generate a separate build specifically for browser environments. They did not know that we try to import a module which actually does not exist. The main challenge we're facing is with Next.js's handling of module imports in the build process. Specifically, the bundler recognizes the import, tries to resolve the module to prevent later issues and throws an error when it can't find the package, even when the import is wrapped in a try-catch block. The try-catch block only applies when we actually try to import the module at runtime. Our workaround involves wrapping the dynamic import so that the import is only evaluated at runtime. This way, the build tools do not try to locate the module and the try-catch block functions as expected. |
anyone reviews this and get it merged? |
2e4960a
to
471995e
Compare
@jeffchuber I am happy with the PR now, we could merge it :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks! a couple questions. I tested locally and works great
@perzeuss why do we need to pin to the older version of |
@jeffchuber there is a breaking change with openai@^4 I changed the pinning because actually we just care about the major versions. |
@perzeuss thanks again for this! i was testing this tonight with https://github.com/jeffchuber/nextjs-chroma/
But it's throwing this error - I can confirm that |
@perzeuss @jeffchuber How is it looking? After this update, langchain also requires dependency update. Right now, everything breaks unfortunately on nextjs. |
@jeffchuber you need to use the import syntax to import the esm build. |
f905453
to
40a94c5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this works! 🎉 just need to remove the dupe fn
in utils
40a94c5
to
0946be5
Compare
resolves chroma-core#953 ## Description of changes - Bug fixes - implement a workaround in clients/js/src/embeddings/WebAIEmbeddingFunction.ts to resolve chroma-core#953 ## Test plan At present, we lack a testing setup specifically tailored for a browser environment. Implementing this would be a necessary step to implement tests for changes in this branch. I've tested it locally using this change: https://github.com/jeffchuber/nextjs-chroma/pull/1/files - http://localhost:3000/api/hello (node version) works fine - http://localhost:3000 (browser version) works fine
resolves chroma-core#953 ## Description of changes - Bug fixes - implement a workaround in clients/js/src/embeddings/WebAIEmbeddingFunction.ts to resolve chroma-core#953 ## Test plan At present, we lack a testing setup specifically tailored for a browser environment. Implementing this would be a necessary step to implement tests for changes in this branch. I've tested it locally using this change: https://github.com/jeffchuber/nextjs-chroma/pull/1/files - http://localhost:3000/api/hello (node version) works fine - http://localhost:3000 (browser version) works fine
resolves chroma-core#953 ## Description of changes - Bug fixes - implement a workaround in clients/js/src/embeddings/WebAIEmbeddingFunction.ts to resolve chroma-core#953 ## Test plan At present, we lack a testing setup specifically tailored for a browser environment. Implementing this would be a necessary step to implement tests for changes in this branch. I've tested it locally using this change: https://github.com/jeffchuber/nextjs-chroma/pull/1/files - http://localhost:3000/api/hello (node version) works fine - http://localhost:3000 (browser version) works fine
resolves #953
Description of changes
npm
:chromadb
insidenextjs
#953Test plan
At present, we lack a testing setup specifically tailored for a browser environment. Implementing this would be a necessary step to implement tests for changes in this branch.
I've tested it locally using this change: https://github.com/jeffchuber/nextjs-chroma/pull/1/files