langchain-ai / langchainjs

🦜🔗 Build context-aware reasoning applications 🦜🔗
https://js.langchain.com/docs/
MIT License
12.31k stars 2.08k forks source link

error TS1452: 'resolution-mode' assertions are only supported when `moduleResolution` is `node16` or `nodenext`. #3453

Closed hirocsingh closed 9 months ago

hirocsingh commented 9 months ago

I am getting the following error while compiling my project. image

error TS1452: 'resolution-mode' assertions are only supported when `moduleResolution` is `node16` or `nodenext`.

Used following command to install langchain

npm i -S langchain
Version: 0.0.198

Running following versions on my system.

TS Configuration as follows:

{
  "compilerOptions": {
    "target": "es2020",
    "module": "nodenext",                               
    "moduleResolution": "nodenext",
    "esModuleInterop": true,                             
    "forceConsistentCasingInFileNames": true,            
    "strict": true,  
    "skipLibCheck": true                                 
  }
}
dosubot[bot] commented 9 months ago

🤖

Hello @hirocsingh!

I'm Dosu, a bot here to assist you with bugs, answer questions, and help you become a contributor to the langchainjs project. While we wait for a human maintainer, feel free to ask me anything related to this repository. Let's make your coding journey a smooth one!

Based on the error message you're encountering and the information you've provided, it seems like your TypeScript version might be causing the issue. Even though your tsconfig.json file is correctly configured with "moduleResolution": "nodenext", the error message suggests that the TypeScript compiler is not recognizing this setting. This could be due to your TypeScript version not supporting the nodenext value for moduleResolution.

The nodenext option was introduced in TypeScript 4.5 to support Node.js's new module resolution strategy, which allows package.json to specify exports and imports. Since you're using Node version 20.1.0, which supports this new module resolution strategy, you should upgrade your TypeScript version to 4.5 or later to resolve this issue.

You can upgrade TypeScript by running the following command:

npm install --save-dev typescript@latest

This will install the latest version of TypeScript as a devDependency in your project. After upgrading TypeScript, try compiling your project again. The error should be resolved.

Additionally, I found two similar issues in the langchainjs repository that might be helpful:

  1. Dependencies are not installed with npm i langchain and resolution-mode issue
  2. build error in typescript and expressJS

These issues suggest modifying your tsconfig.json file and ensuring you have the correct dependencies installed. You might find the discussions and solutions proposed in these issues helpful.

Please try these solutions and let me know if the issue persists. I'm here to help!

Sources

hirocsingh commented 9 months ago

@dosubot

My Typescript version is 5.1.3 which higher than 4.5 which you suggested.

dosubot[bot] commented 9 months ago

🤖

Based on the information you've provided and the similar issues I found in the langchainjs repository, it seems like the error error TS1452: 'resolution-mode' assertions are only supported whenmoduleResolutionisnode16ornodenext. might be due to a few potential reasons.

Firstly, it's worth noting that the moduleResolution option in your TypeScript configuration (tsconfig.json) is set to nodenext, which is correct as per the error message. However, the resolution-mode assertions are only supported in TypeScript 4.5 and later versions. You mentioned that your TypeScript version is 5.1.3, which should be compatible. However, as of the time of writing, the latest stable release of TypeScript is 4.5.2. Therefore, it seems there might be a mistake in your TypeScript version number. You can check your TypeScript version by running tsc -v in your terminal. If you are not using TypeScript 4.5 or later, you can update it by running npm install -g typescript@latest.

If you are already using TypeScript 4.5 or later and still encountering this error, it might be due to a compatibility issue between the LangChain Javascript framework and your TypeScript version. According to the package.json file in the langchainjs repository, the exact version of TypeScript that is compatible with the LangChain Javascript framework version 0.0.198 is TypeScript version 5.0.0.

In addition to checking your TypeScript version, there are a few other steps you can take to potentially resolve this issue:

  1. Add "skipLibCheck": true to your tsconfig.json file. This will skip type checking of all declaration files (*.d.ts).
  2. Delete the tsconfi.eslint.json file.
  3. Update your TypeScript configuration by adding "moduleResolution": "node16" to your tsconfig.json file.
  4. Install missing dependencies using npm or yarn. For example:
npm install cohere-ai@6.0.0
npm install chromadb
npm install @huggingface/inference
npm install replicate
npm install @supabase/supabase-js
npm install @supabase/postgrest-js
  1. Ensure you have the latest version of langchainjs installed: Uninstall the current version using npm uninstall langchain and then reinstall it using npm install -S langchain.
  2. Use Yarn for dependency management: The langchainjs project is configured to use Yarn as its package manager. If you're not already using Yarn, you can install it with npm install -g yarn and then run yarn install to install the project dependencies.
  3. Ensure you're using the correct Node.js version: The minimum required version of Node.js for the langchainjs repository is 20. You can check your Node.js version with node -v and update it if necessary.

These solutions were suggested in the following issues:

I hope this helps! If you're still encountering issues after trying these steps, please provide more information about your setup and the exact steps you're taking when you encounter the error.

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.

hirocsingh commented 9 months ago

Updating to following configuration worked.