langchain-ai / langchainjs

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

build error in typescript and expressJS #1293

Closed anandsthajp closed 1 year ago

anandsthajp commented 1 year ago

"typescript": "^4.9.4" "langchain": "^0.0.74",

whenever I am trying build for prod, I'm always getting error related to langchain, my tsconfg.json

{
  "compilerOptions": {
    "lib": ["es2022", "DOM"],
    "module": "commonjs",
    "target": "es2022",
    "isolatedModules": true,
    "allowJs": false,
    "strict": true,
    "esModuleInterop": true,
    "skipLibCheck": true,
    "forceConsistentCasingInFileNames": true,
    "allowSyntheticDefaultImports": true,
    "noImplicitReturns": true,
    "noImplicitAny": true,
    "moduleResolution": "node",
    "sourceMap": true,
    "outDir": "dist",
    "strictNullChecks": true,
    "noUncheckedIndexedAccess": true,
    "resolveJsonModule": true
  },
  "include": ["src"],
  "exclude": ["node_modules", "dist"]
}

There are like 41 errors all related to langchain. eg: node_modules/langchain/dist/document_loaders/fs/buffer.d.ts:1:23 - error TS1452: 'resolution-mode' assertions are only supported when moduleResolution is node16 or nodenext.

1 ///

node_modules/langchain/dist/document_loaders/fs/epub.d.ts:1:27 - error TS2307: Cannot find module 'epub2' or its corresponding type declarations.

1 import type { EPub } from "epub2";

node_modules/puppeteer/lib/types.d.ts:2280:5 - error TS18028: Private identifiers are only available when targeting ECMAScript 2015 and higher.

2280 #private;

Note: Even though I make any changes on tsconfig.json like target to node16 or node next, I don't see any affects.

nfcampos commented 1 year ago

can you confirm which langchain imports you have in your application?

Also see https://github.com/hwchase17/langchainjs/tree/main/test-exports-cjs for an example CJS Node.js project tested on CI to work

anandsthajp commented 1 year ago

@nfcampos BaseDocumentLoader, PDFLoader, Pinecone, zeroshot agents and so on. I removed my tsconfig.eslint.json and changed my tsconfig.json to the following, it seems to be working. Somehow tsconfig.eslint.json didn't allow it to have any impact even though I changed setting on tsconfig file, and not sure why it was affecting only langchain.

{
  "compilerOptions": {
    "lib": ["ESNext", "DOM"],
    "module": "commonjs",
    "target": "ES6",
    "strict": true,
    "esModuleInterop": true,
    "skipLibCheck": true,
    "forceConsistentCasingInFileNames": true,
    "strictNullChecks": true,
    "allowSyntheticDefaultImports": true,
    "noImplicitReturns": true,
    "noImplicitAny": true,
    "resolveJsonModule": true
  },
  "include": ["src"],
  "exclude": ["node_modules", "./husky"]
}
nfcampos commented 1 year ago

Cool, great that it was resolved

mhassanpur commented 1 year ago

Just to add to expand on @anandsthajp's solution, the specific setting that worked for me is adding skipLibCheck: true in my tsconfig.json file.