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

Unable to build app due to langchain-js files #7381

Open
5 tasks done
Sajid2001 opened this issue Dec 16, 2024 · 3 comments
Open
5 tasks done

Unable to build app due to langchain-js files #7381

Sajid2001 opened this issue Dec 16, 2024 · 3 comments
Labels
auto:bug Related to a bug, vulnerability, unexpected error with an existing feature

Comments

@Sajid2001
Copy link

Checked other resources

  • I added a very descriptive title to this issue.
  • I searched the LangChain.js documentation with the integrated search.
  • I used the GitHub search to find a similar question and didn't find it.
  • I am sure that this is a bug in LangChain.js rather than my code.
  • The bug is not resolved by updating to the latest stable version of LangChain (or the specific integration package).

Example Code

package.json

{
  "name": "monolith",
  "version": "1.0.0",
  "description": "",
  "main": "./src/index.ts",
  "scripts": {
    "dev": "nodemon",
    "start": "ts-node ./src/index.ts",
    "build": "tsc"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "@types/bcryptjs": "^2.4.6",
    "@types/body-parser": "^1.19.5",
    "@types/cookie-parser": "^1.4.7",
    "@types/cors": "^2.8.17",
    "@types/express": "^4.17.21",
    "@types/jsonwebtoken": "^9.0.7",
    "@types/luxon": "^3.4.2",
    "@types/morgan": "^1.9.9",
    "@types/multer": "^1.4.12",
    "@types/node": "^22.5.5",
    "@types/nodemailer": "^6.4.16",
    "@types/ws": "^8.5.13",
    "nodemon": "^3.1.7",
    "ts-node": "^10.9.2",
    "typescript": "^5.6.2"
  },
  "dependencies": {
    "@aws-sdk/client-dynamodb": "^3.712.0",
    "@aws-sdk/util-dynamodb": "^3.712.0",
    "@deepgram/sdk": "^3.9.0",
    "@langchain/core": "^0.3.18",
    "@langchain/openai": "^0.3.13",
    "bcryptjs": "^2.4.3",
    "body-parser": "^1.20.3",
    "cookie-parser": "^1.4.6",
    "cors": "^2.8.5",
    "date-fns": "^4.1.0",
    "dotenv": "^16.4.5",
    "express": "^4.21.0",
    "jsonwebtoken": "^9.0.2",
    "langchain": "^0.3.6",
    "luxon": "^3.5.0",
    "morgan": "^1.10.0",
    "multer": "1.4.5-lts.1",
    "nodemailer": "^6.9.16",
    "socket.io": "^4.8.1",
    "stripe": "^17.2.1",
    "uuid": "^11.0.3"
  }
}

tsconfig.json

{
  "compilerOptions": {
    "target": "ES2020",
    "module": "NodeNext",
    "moduleResolution": "NodeNext",
    "sourceMap": true,
    "noImplicitAny": true,
    "outDir": "./dist",
    "strict": true,
    "typeRoots": ["./src/types", "./node_modules/@types"]
  },
  "include": ["src/**/*"]
}

Error Message and Stack Trace (if applicable)

PS C:\Users\sajid\Desktop\med startup tests\voice_transcription\monolith> pnpm run build

[email protected] build C:\Users\sajid\Desktop\med startup tests\voice_transcription\monolith
tsc

node_modules/.pnpm/@langchain[email protected][email protected][email protected]_/node_modules/@langchain/core/output_parsers.d.cts:1:15 - error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("./dist/output_parsers/index.js")' call instead.

1 export * from './dist/output_parsers/index.js'
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

node_modules/.pnpm/@langchain[email protected][email protected][email protected]_/node_modules/@langchain/core/prompts.d.cts:1:15 - error TS1479: The current file is
a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("./dist/prompts/index.js")' call instead.

1 export * from './dist/prompts/index.js'
~~~~~~~~~~~~~~~~~~~~~~~~~

node_modules/.pnpm/@langchain+openai@0.3.13_@langchain+core@0._2atobctgv6vhmnci3yzbqkkle4/node_modules/@langchain/openai/index.d.cts:1:15 - error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("./dist/index.js")' call instead.

1 export * from './dist/index.js'
~~~~~~~~~~~~~~~~~

Found 3 errors in 3 files.

Errors Files
1 node_modules/.pnpm/@langchain[email protected][email protected][email protected]_/node_modules/@langchain/core/output_parsers.d.cts:1
1 node_modules/.pnpm/@langchain[email protected][email protected][email protected]_/node_modules/@langchain/core/prompts.d.cts:1
1 node_modules/.pnpm/@langchain+openai@0.3.13_@langchain+core@0._2atobctgv6vhmnci3yzbqkkle4/node_modules/@langchain/openai/index.d.cts:1
 ELIFECYCLE  Command failed with exit code 2.

Description

I am trying to build my typescript node server, but it's not building because of the langchain modules. I tried {"module": "NodeNext","moduleResolution": "bundler"}, which does build the app, but then I get even more issues running that build, such as every file not having a .js at the end, among other issues.

System Info

pnpm version 9.12.3
node version v20.12.0
Windows 10

@dosubot dosubot bot added the auto:bug Related to a bug, vulnerability, unexpected error with an existing feature label Dec 16, 2024
Copy link

dosubot bot commented Dec 16, 2024

Hey @Sajid2001! I'm here to help you with any bugs, questions, or contributions. Let's dive into this together!

I found some similar discussions that might help you resolve the issue:

  1. Vite v5 react cannot build: Error: [commonjs--resolver] Failed to resolve entry for package "@langchain/core". The package may have incorrect main/module/exports specified in its package.json - This discussion is unsolved but highlights similar issues with module resolution.

  2. I'm getting this Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './dist/tools/json' is not defined by "exports" in node_modules\langchain\package.json (working with typescript code) - Another unsolved discussion that deals with module export issues.

To address the TypeScript build errors related to CommonJS and ECMAScript module imports, you can try using dynamic imports. Modify your code to use the import() function, which returns a promise. This function can be used in an async function to import the module and use it in your code. Here's an example:

export const getExamples = async (query: string, apiKey: string) => {
  const { MemoryVectorStore } = await import("langchain/vectorstores/memory");
  const { OpenAIEmbeddings } = await import("langchain/embeddings/openai");

  // Rest of your code...
};

Additionally, ensure that your tsconfig.json is configured correctly. You might need to set "module": "nodenext" and "moduleResolution": "nodenext" to help TypeScript understand the module system you are using and resolve imports correctly [1].

To continue talking to Dosu, mention @dosu.


Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Other

@jacoblee93
Copy link
Collaborator

Hi, giving this a go now

@jacoblee93
Copy link
Collaborator

Hey @Sajid2001, I tried to make a minimal reproducible example like this:

https://github.com/jacoblee93/pnpm-testing

But was unable to repro. Can you share some of your application code?

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