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": "^0.1.2", Cannot find module 'langchain/llms', #4019

Closed
zwilch opened this issue Jan 15, 2024 · 3 comments
Closed

"langchain": "^0.1.2", Cannot find module 'langchain/llms', #4019

zwilch opened this issue Jan 15, 2024 · 3 comments
Labels
auto:bug Related to a bug, vulnerability, unexpected error with an existing feature

Comments

@zwilch
Copy link

zwilch commented Jan 15, 2024

node -v v20.10.0
npm -v 10.2.5

followed this simple tutorial: https://langchainers.hashnode.dev/getting-started-with-langchainjs

Error:

Cannot find module 'langchain/llms' or its corresponding type declarations.
1 import { OpenAI } from 'langchain/llms'

package.json

{
  "name": "",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "type": "module",
  "license": "AGPL-version-3.0",
  "private": false,
  "engines": {
    "node": ">= 20.10.0",
    "npm": ">= 10.2.5"
  },
  "homepage": "",
  "repository": {
    "type": "git",
    "url": ""
  },
  "bugs": "",
  "keywords": [],
  "author": {
    "name": "",
    "email": "",
    "url": ""
  },
  "contributors": [],
  "scripts": {
    "build": "tsc",
    "start": "node ./dist/app.js",
    "dev": "ts-node --esm ./src/app.ts"
  },
  "dependencies": {
    "@types/node": "^20.11.1",
    "dotenv": "^16.3.1",
    "langchain": "^0.1.2",
    "openai": "^4.24.7",
    "typescript": "^5.3.3"
  },
  "devDependencies": {
    "ts-node": "^10.9.2"
  }
}

Copy link

dosubot bot commented Jan 15, 2024

🤖

Hello @zwilch! I'm Dosu, your friendly bot here to assist you with bug troubleshooting, answering questions, and guiding you on becoming a fantastic contributor while we're waiting for a human maintainer. I'm ready to help you out with your langchainjs issue. Let's dive into it together!

Based on the context provided, it seems like you're encountering an issue with importing the OpenAI module from langchain/llms in your project using langchain version 0.1.2. This issue has been reported before in the langchainjs repository, specifically in the issues: Issue importing submodules using es6 module import from documentation, ECMAScript module cannot be used in CommonJS module, Cannot find module 'langchain/tools/google_calendar', and importing issues..

The error message "Cannot find module 'langchain/llms' or its corresponding type declarations" indicates that the module 'langchain/llms' cannot be found in your project. This could be due to a few reasons:

  1. The module 'langchain/llms' does not exist in the version of langchainjs you are using. It's possible that the 'llms' module was introduced in a later version.
  2. The module 'langchain/llms' is not correctly installed in your project. This could be due to an incorrect installation or a problem with your node_modules folder.
  3. The import path is incorrect. In your case, you are trying to import { OpenAI } from 'langchain/llms'. However, in the example code you provided, the import statement is 'langchain/llms/openai'. This could be the source of the problem.

To fix this issue, you should:

  1. Check the version of langchainjs you are using and make sure it includes the 'llms' module. If it doesn't, you may need to upgrade to a later version.
  2. Make sure the 'langchain/llms' module is correctly installed in your project. You can do this by checking your node_modules folder or by reinstalling the module.
  3. Correct the import path in your code. Based on the example code you provided, the correct import statement should be 'langchain/llms/openai', not 'langchain/llms'. So, your import statement should look like this:
import { OpenAI } from "langchain/llms/openai";

If you've done all of these steps and are still encountering the error, there may be a deeper issue with your project configuration or with the langchainjs library itself.

As for the exact structure of the 'langchain/llms' module in the langchainjs version 0.1.2, I wasn't able to find an answer within the repository. The answer may be available elsewhere or I could have missed it.

I hope this helps! If you have any other questions or need further clarification, feel free to ask.

-Dosu

Sources


This response is meant to be useful and save you time. 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.

If you want to continue the conversation, start your reply with @dosu-bot.

@dosubot dosubot bot added the auto:bug Related to a bug, vulnerability, unexpected error with an existing feature label Jan 15, 2024
@zwilch
Copy link
Author

zwilch commented Jan 15, 2024

Thank you, this
import { OpenAI } from "langchain/llms/openai";
solved the problem.

@zwilch zwilch closed this as completed Jan 15, 2024
@jacoblee93
Copy link
Collaborator

jacoblee93 commented Jan 15, 2024

Glad Dosu solved it, @langchain/openai is the preferred entrypoint now though via the partner package.

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