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

Module not found: Can't resolve 'path' on NextJS edge runtime. #994

Closed
homanp opened this issue Apr 26, 2023 · 9 comments · Fixed by #1034
Closed

Module not found: Can't resolve 'path' on NextJS edge runtime. #994

homanp opened this issue Apr 26, 2023 · 9 comments · Fixed by #1034
Labels
env/packaging Issues related to packaging/bundling question Further information is requested

Comments

@homanp
Copy link

homanp commented Apr 26, 2023

Summary

When running langchainjs on the edge runtime in NextJS I see the following exception:

Error: Module not found: Can't resolve 'path'

https://nextjs.org/docs/messages/module-not-found

Import trace for requested module:
./node_modules/langchain/dist/base_language/count_tokens.js
./node_modules/langchain/dist/llms/openai.js
./node_modules/langchain/llms/openai.js

Currently running version 0.0.63.

@nfcampos
Copy link
Collaborator

@nfcampos nfcampos added the question Further information is requested label Apr 26, 2023
@homanp
Copy link
Author

homanp commented Apr 26, 2023

yep, I use the Next13 appDir route handlers. Perhaps that env differs somehow.

https://beta.nextjs.org/docs/routing/route-handlers

@mushan0x0
Copy link

Me too.

@nfcampos nfcampos added the env/packaging Issues related to packaging/bundling label Apr 27, 2023
@Nedomas
Copy link

Nedomas commented Apr 28, 2023

I believe it's because of this line:
https://github.com/hwchase17/langchainjs/blob/main/langchain/src/base_language/count_tokens.ts#L62
Additionally imported modules raise error on this line too: https://github.com/hwchase17/langchainjs/blob/main/langchain/src/text_splitter.ts#L1, there might be more related to tiktoken.

Not sure why - maybe Next.js 13 app dir route handlers with runtime: 'edge' import files differently?

Commenting this line fixes the error.

@nfcampos should tiktoken work with langchain on the edge or should we be skipping imports of it?

Version: 0.0.64

@nfcampos
Copy link
Collaborator

Ah interesting, thanks for investigating!

@dqbd any thoughts on this one? Would it be fixed/fixable with #847

@dqbd
Copy link
Collaborator

dqbd commented Apr 28, 2023

Hello! That definitely sounds like an issue with @dqbd/tiktoken, will address it as soon as possible.
This does to be a different issue than found in #847

@nfcampos
Copy link
Collaborator

Cool, thank you!

@dqbd
Copy link
Collaborator

dqbd commented Apr 28, 2023

Added a quick fix for both @dqbd/tiktoken and langchain
#1034

Please note, that until #847 is done and merged, the bundle size will be larger than the recommended 1 MB limit. WIll finish the PR in the upcoming days.

@nfcampos
Copy link
Collaborator

Thanks @dqbd ! This has been released as 0.0.66

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
env/packaging Issues related to packaging/bundling question Further information is requested
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants