langchainjs: [ERROR] Langchain in typescript can't find a bunch of modules!
Hi. I installed langchain for my Node Typescript project. When I try to run the sample, I get the following errors in the terminal:
node_modules/langchain/dist/cache.d.ts:1:38 - error TS2307: Cannot find module 'redis' or its corresponding type declarations.
1 import type { RedisClientType } from "redis";
~~~~~~~
node_modules/langchain/dist/embeddings/cohere.d.ts:54:31 - error TS2307: Cannot find module 'cohere-ai' or its corresponding type declarations.
54 cohere: typeof import("cohere-ai");
~~~~~~~~~~~
node_modules/langchain/dist/llms/cohere.d.ts:21:31 - error TS2307: Cannot find module 'cohere-ai' or its corresponding type declarations.
21 cohere: typeof import("cohere-ai");
~~~~~~~~~~~
node_modules/langchain/dist/llms/hf.d.ts:29:36 - error TS2307: Cannot find module '@huggingface/inference' or its corresponding type declarations.
29 HfInference: typeof import("@huggingface/inference").HfInference;
~~~~~~~~~~~~~~~~~~~~~~~~
node_modules/langchain/dist/llms/openai-chat.d.ts:2:15 - error TS2614: Module '"../util/axios-fetch-adapter.js"' has no exported member 'StreamingAxiosConfiguration'. Did you mean to use 'import StreamingAxiosConfiguration from "../util/axios-fetch-adapter.js"' instead?
2 import type { StreamingAxiosConfiguration } from "../util/axios-fetch-adapter.js";
~~~~~~~~~~~~~~~~~~~~~~~~~~~
node_modules/langchain/dist/llms/openai.d.ts:2:15 - error TS2614: Module '"../util/axios-fetch-adapter.js"' has no exported member 'StreamingAxiosConfiguration'. Did you mean to use 'import StreamingAxiosConfiguration from "../util/axios-fetch-adapter.js"' instead?
2 import type { StreamingAxiosConfiguration } from "../util/axios-fetch-adapter.js";
~~~~~~~~~~~~~~~~~~~~~~~~~~~
node_modules/langchain/dist/llms/replicate.d.ts:17:34 - error TS2307: Cannot find module 'replicate' or its corresponding type declarations.
17 Replicate: typeof import("replicate").Replicate;
~~~~~~~~~~~
node_modules/langchain/dist/sql_db.d.ts:1:67 - error TS2307: Cannot find module 'typeorm' or its corresponding type declarations.
1 import type { DataSource as DataSourceT, DataSourceOptions } from "typeorm";
~~~~~~~~~
node_modules/langchain/dist/text_splitter.d.ts:1:32 - error TS2307: Cannot find module '@dqbd/tiktoken' or its corresponding type declarations.
1 import type * as tiktoken from "@dqbd/tiktoken";
~~~~~~~~~~~~~~~~
node_modules/langchain/dist/util/sql_utils.d.ts:1:52 - error TS2307: Cannot find module 'typeorm' or its corresponding type declarations.
1 import type { DataSource, DataSourceOptions } from "typeorm";
~~~~~~~~~
node_modules/langchain/dist/vectorstores/chroma.d.ts:1:52 - error TS2307: Cannot find module 'chromadb' or its corresponding type declarations.
1 import type { ChromaClient as ChromaClientT } from "chromadb";
~~~~~~~~~~
node_modules/langchain/dist/vectorstores/hnswlib.d.ts:1:69 - error TS2307: Cannot find module 'hnswlib-node' or its corresponding type declarations.
1 import type { HierarchicalNSW as HierarchicalNSWT, SpaceName } from "hnswlib-node";
~~~~~~~~~~~~~~
node_modules/langchain/dist/vectorstores/pinecone.d.ts:1:42 - error TS2307: Cannot find module '@pinecone-database/pinecone/dist/pinecone-generated-ts-fetch' or its corresponding type declarations.
1 import type { VectorOperationsApi } from "@pinecone-database/pinecone/dist/pinecone-generated-ts-fetch";
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
node_modules/langchain/dist/vectorstores/supabase.d.ts:1:37 - error TS2307: Cannot find module '@supabase/supabase-js' or its corresponding type declarations.
1 import type { SupabaseClient } from "@supabase/supabase-js";
~~~~~~~~~~~~~~~~~~~~~~~
Found 14 errors in 14 files.
Errors Files
1 ../../../../../users/adityam/documents/code/node-sandbox/node_modules/langchain/dist/cache.d.ts:1
1 ../../../../../users/adityam/documents/code/node-sandbox/node_modules/langchain/dist/embeddings/cohere.d.ts:54
1 ../../../../../users/adityam/documents/code/node-sandbox/node_modules/langchain/dist/llms/cohere.d.ts:21
1 ../../../../../users/adityam/documents/code/node-sandbox/node_modules/langchain/dist/llms/hf.d.ts:29
1 ../../../../../users/adityam/documents/code/node-sandbox/node_modules/langchain/dist/llms/openai-chat.d.ts:2
1 ../../../../../users/adityam/documents/code/node-sandbox/node_modules/langchain/dist/llms/openai.d.ts:2
1 ../../../../../users/adityam/documents/code/node-sandbox/node_modules/langchain/dist/llms/replicate.d.ts:17
1 ../../../../../users/adityam/documents/code/node-sandbox/node_modules/langchain/dist/sql_db.d.ts:1
1 ../../../../../users/adityam/documents/code/node-sandbox/node_modules/langchain/dist/text_splitter.d.ts:1
1 ../../../../../users/adityam/documents/code/node-sandbox/node_modules/langchain/dist/util/sql_utils.d.ts:1
1 ../../../../../users/adityam/documents/code/node-sandbox/node_modules/langchain/dist/vectorstores/chroma.d.ts:1
1 ../../../../../users/adityam/documents/code/node-sandbox/node_modules/langchain/dist/vectorstores/hnswlib.d.ts:1
1 ../../../../../users/adityam/documents/code/node-sandbox/node_modules/langchain/dist/vectorstores/pinecone.d.ts:1
1 ../../../../../users/adityam/documents/code/node-sandbox/node_modules/langchain/dist/vectorstores/supabase.d.ts:1
I did do npm install -S langchain. And I set all the parameters in the tsconfig.json & package.json to the recommended values.
Here is my package.json:
{
"name": "sandbox",
"version": "1.0.0",
"description": "NodeJS sandbox.",
"main": "dist/index.js",
"type": "module",
"scripts": {
"start": "node dist/index.js",
"build": "tsc && npm run start"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"langchain": "^0.0.47"
},
"devDependencies": {
"@types/node": "^18.15.11"
}
}
And here is my tsconfig.json:
{
"compilerOptions": {
"target": "ES2020",
"module": "NodeNext",
"sourceMap": true,
"outDir": "./dist",
"strict": true,
"esModuleInterop": true,
"moduleResolution": "nodenext"
},
"include": [
"./src/**/*",
"./assets/**/*"
],
"exclude": [
"node_modules"
]
}
What’s going on? Will I have to install all these modules separately?
About this issue
- Original URL
- State: closed
- Created a year ago
- Reactions: 2
- Comments: 15
You can make it work by adding
"skipLibCheck": trueto your tsconfig.json, see https://github.com/nfcampos/langchain-issue-602Stumbled passed this issue today. I found for some reason my
package.jsonwas had"langchain": "^0.0.39"installed for some reason (old library doesn’t know what the latest modules are, before it’s time). Since I was usingnpmI rannpm uninstall langchainand then reinstalled withnpm install -S langchain. This installed"langchain": "^0.0.97",Then my lost module party was over. Hope this helps.I was getting the same error but after installing the exact version
"langchain": "^0.0.97"given by @ianmcfall I was able to succeed! Make sure you have uninstalled the manually installedcohere-aiwhen you do thisThis is still happening in the latest version 133 and is not solved for me with uninstall, reinstall (with or without -S), or wiping the npm cache. The missing packages are cohere-ai, @huggingface/inference, and replicate. If we look in the package.json file line 646 https://www.npmjs.com/package/langchain/v/0.0.133?activeTab=code
we see that cohere is listed as a DEV dependency. I don’t think langchain’s dev dependencies are installed for
npm i langchain(the command given on the langchain homepage on npm). This is probably why people are hitting errors. I suppose to get around the problem the packages could be added to our own package.json files.I am hitting the same errors where it is declaring types as what the OP showed. I have no idea how many packages will be needed to be installed to prevent the type errors.
Thanks @ianmcfall , Good work my friend, you are a time saver. Can’t thank you enough.
i have the same issue and i want to use this repo for production, i cannot use skipLibCheck, any other idea?
I am using Typescript Version 4.8.2. Do I need to upgrade?
Also, here is my code in
index.ts. As you can see, I’m just doing the basicstate_of_the_unionexample: