Skip to content

Commit

Permalink
Add support for Node 20.x (langchain-ai#876)
Browse files Browse the repository at this point in the history
* Add support for Node 20.x

* Disable test-exports-cra test on nodejs 20 due incompatibilities in jsdom/canvas which are outside of our remit

* Nit

* Disable pdfjs test in node 20
  • Loading branch information
nfcampos authored Apr 26, 2023
1 parent 767174d commit 00bb72a
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 4 deletions.
8 changes: 5 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ jobs:
strategy:
matrix:
os: [macos-latest, windows-latest, ubuntu-latest]
node-version: [18.x, 19.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
node-version: [18.x, 19.x, 20.x]
# See Node.js release schedule at https://nodejs.org/en/about/releases/
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
Expand All @@ -74,7 +74,9 @@ jobs:
- name: Build
run: yarn run build --filter="!docs"
- name: Test
run: yarn run test:unit
run: yarn run test:unit --filter="!test-exports-cra"
# test-exports-cra is still run in test-exports task, currently not
# compatible with Node.js 20.x, so disabling here

test-exports:
name: Environment Tests
Expand Down
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@ Please fill out [this form](https://forms.gle/57d8AmXBYp8PP8tZA) and we'll set u
import { OpenAI } from "langchain/llms/openai";
```

## Supported Environments

LangChain is written in TypeScript and can be used in:

- Node.js (ESM and CommonJS) - 18.x, 19.x, 20.x
- Cloudflare Workers
- Vercel / Next.js (Browser, Serverless and Edge functions)
- Supabase Edge Functions
- Browser
- Deno

## 🤔 What is this?

Large language models (LLMs) are emerging as a transformative technology, enabling
Expand Down
13 changes: 12 additions & 1 deletion docs/docs/getting-started/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,17 @@ sidebar_position: 1
Updating from <0.0.52? See [this section](#updating-from-0052) for instructions.
:::

## Supported Environments

LangChain is written in TypeScript and can be used in:

- Node.js (ESM and CommonJS) - 18.x, 19.x, 20.x
- Cloudflare Workers
- Vercel / Next.js (Browser, Serverless and Edge functions)
- Supabase Edge Functions
- Browser
- Deno

## Quickstart

If you want to get started quickly on using LangChain in Node.js, [clone this repository](https://github.com/domeccleston/langchain-ts-starter) and follow the README instructions for a boilerplate project with those dependencies set up.
Expand Down Expand Up @@ -178,4 +189,4 @@ You will have to make `fetch` available globally, either:

Additionally you'll have to polyfill `unstructuredClone`, eg. by installing `core-js` and following the instructions [here](https://github.com/zloirock/core-js).

If you are running this on Node.js 18 or 19, you do not need to do anything.
If you are running this on Node.js 18+, you do not need to do anything.
4 changes: 4 additions & 0 deletions langchain/src/document_loaders/tests/pdf.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ test("Test PDF loader from file to single document", async () => {
});

test("Test PDF loader from file using custom pdfjs", async () => {
if (process.version.startsWith("v20")) {
// `pdfjs-dist` doesn't support Node 20 (`canvas` doesn't support Node 20)
return;
}
const filePath = path.resolve(
path.dirname(url.fileURLToPath(import.meta.url)),
"./example_data/1706.03762.pdf"
Expand Down

0 comments on commit 00bb72a

Please sign in to comment.