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

langchain in commonjs come up a error #1943

Closed
kill136 opened this issue Jul 12, 2023 · 2 comments
Closed

langchain in commonjs come up a error #1943

kill136 opened this issue Jul 12, 2023 · 2 comments
Assignees
Labels
auto:bug Related to a bug, vulnerability, unexpected error with an existing feature

Comments

@kill136
Copy link

kill136 commented Jul 12, 2023

in commonjs environment,call langchain like below:
const {
OpenAI,
OpenAIChat
} = require("langchain/llms/openai");

#################################
Unexpected token export\n/var/user/node_modules/langchain/llms/openai.js:1\n(function (exports, require, module, __filename, __dirname) { export * from '../dist/llms/openai.js'\n ^^^^^^\n\nSyntaxError: Unexpected token export\n at createScript (vm.js:80:10)\n at Object.runInThisContext (vm.js:139:10)\n at Module._compile (module.js:607:28)\n at Object.Module._extensions..js (module.js:654:10)\n at Module.load (module.js:556:32)\n at tryModuleLoad (module.js:499:12)\n at Function.Module._load (module.js:491:3)\n at Module.require (module.js:587:17)\n at require (internal/module.js:11:18)\n

@dosubot dosubot bot added the auto:bug Related to a bug, vulnerability, unexpected error with an existing feature label Jul 12, 2023
@dosubot
Copy link

dosubot bot commented Jul 12, 2023

Answer generated by a 🤖

Answer

I found related issues that might be helpful. I did my best to summarize the solutions, but I recommend looking at the related issues yourself.

Closed Issues

Error: Cannot find module 'langchain/llms/openai' code: 'MODULE_NOT_FOUND'

The suggested solution is: Move the LangChain dependency from the devDependencies list to the dependencies list in your package.json file.


This response is meant to be useful, save you time, and share context. It is not meant to be a precise solution, but rather a starting point for your own research.

Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

@jacoblee93
Copy link
Collaborator

jacoblee93 commented Jul 12, 2023

Happy to try to help? Which version of LangChain are you running?

Just tried with a starter Nest.js project (running CommonJS) with the latest version (0.0.107) and it seemed to work ok:

https://github.com/jacoblee93/langchain-nest-test

https://github.com/jacoblee93/langchain-nest-test/blob/master/src/app.controller.ts#L3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto:bug Related to a bug, vulnerability, unexpected error with an existing feature
Projects
None yet
Development

No branches or pull requests

2 participants