Skip to content

Commit d221617

Browse files
authored
Merge pull request #626 from hwchase17/nc/cjs-build
Add CJS build, add package testing CJS exports
2 parents a5eeaff + 010fd18 commit d221617

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+734
-209
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,5 @@ jobs:
7373
run: yarn install --immutable
7474
- name: Build
7575
run: yarn run build --filter="!docs"
76-
- name: Test exports
77-
run: yarn workspace test-exports run test
78-
- name: Test langchain
79-
run: yarn workspace langchain run test
76+
- name: Test
77+
run: yarn run test:unit

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
node_modules/
22
dist/
3+
dist-cjs/
34
lib/
45
.turbo
56
.eslintcache

.watchmanconfig

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"ignore_dirs": [
3+
"langchain/dist",
4+
"langchain/dist-cjs",
5+
"docs/build",
6+
"node_modules",
7+
"langchain/.turbo",
8+
"docs/.turbo",
9+
"test-exports/.turbo",
10+
"test-exports-cjs/.turbo"
11+
]
12+
}

docs/docs/getting-started/install.md

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -24,47 +24,38 @@ We currently support LangChain on Node.js 18 and 19. Go [here](https://github.co
2424

2525
### TypeScript
2626

27-
If you are using TypeScript we suggest updating your `tsconfig.json` to include the following:
28-
29-
```json
30-
{
31-
"compilerOptions": {
32-
...
33-
"target": "ES2020", // or higher
34-
"module": "nodenext",
35-
}
36-
}
37-
```
27+
LangChain is written in TypeScript and provides type definitions for all of its public APIs.
3828

3929
## Loading the library
4030

4131
### ESM in Node.js
4232

43-
LangChain is an ESM library currently targeting Node.js environments. To use it, you will need to use the `import` syntax, inside a project with `type: module` in its `package.json`.
44-
45-
```typescript
46-
import { OpenAI } from "langchain";
47-
```
48-
49-
### CommonJS in Node.js
50-
51-
If your project is using CommonJS, you can use LangChain only with the dynamic `import()` syntax.
33+
LangChain provides an ESM build targeting Node.js environments. You can import it using the following syntax:
5234

5335
```typescript
54-
const { OpenAI } = await import("langchain");
36+
import { OpenAI } from "langchain/llms";
5537
```
5638

57-
If you're using TypeScript in a CommonJS project, you'll need to add the following to your `tsconfig.json`:
39+
If you are using TypeScript in an ESM project we suggest updating your `tsconfig.json` to include the following:
5840

5941
```json
6042
{
6143
"compilerOptions": {
6244
...
63-
"moduleResolution": "node16",
45+
"target": "ES2020", // or higher
46+
"module": "nodenext",
6447
}
6548
}
6649
```
6750

51+
### CommonJS in Node.js
52+
53+
LangChain provides a CommonJS build targeting Node.js environments. You can import it using the following syntax:
54+
55+
```typescript
56+
const { OpenAI } = require("langchain/llms");
57+
```
58+
6859
### Other environments
6960

7061
LangChain currently supports only Node.js-based environments. This includes Vercel Serverless functions (but not Edge functions), as well as other serverless environments, like AWS Lambda and Google Cloud Functions.

examples/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,4 @@
2929
"include": [
3030
"./src"
3131
]
32-
}
32+
}

langchain/.eslintrc.cjs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,13 @@ module.exports = {
1414
plugins: ["@typescript-eslint", "tree-shaking"],
1515
ignorePatterns: [
1616
".eslintrc.cjs",
17-
"create-entrypoints.js",
18-
"check-tree-shaking.js",
17+
"scripts",
1918
"node_modules",
19+
"dist",
20+
"dist-cjs",
21+
"*.js",
22+
"*.cjs",
23+
"*.d.ts",
2024
],
2125
rules: {
2226
"tree-shaking/no-side-effects-in-initialization": [

langchain/.gitignore

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,60 @@
1+
agents.cjs
12
agents.js
23
agents.d.ts
4+
base_language.cjs
35
base_language.js
46
base_language.d.ts
7+
tools.cjs
58
tools.js
69
tools.d.ts
10+
chains.cjs
711
chains.js
812
chains.d.ts
13+
embeddings.cjs
914
embeddings.js
1015
embeddings.d.ts
16+
llms.cjs
1117
llms.js
1218
llms.d.ts
19+
prompts.cjs
1320
prompts.js
1421
prompts.d.ts
22+
vectorstores.cjs
1523
vectorstores.js
1624
vectorstores.d.ts
25+
text_splitter.cjs
1726
text_splitter.js
1827
text_splitter.d.ts
28+
memory.cjs
1929
memory.js
2030
memory.d.ts
31+
document.cjs
2132
document.js
2233
document.d.ts
34+
docstore.cjs
2335
docstore.js
2436
docstore.d.ts
37+
document_loaders.cjs
2538
document_loaders.js
2639
document_loaders.d.ts
40+
chat_models.cjs
2741
chat_models.js
2842
chat_models.d.ts
43+
schema.cjs
2944
schema.js
3045
schema.d.ts
46+
sql_db.cjs
3147
sql_db.js
3248
sql_db.d.ts
49+
callbacks.cjs
3350
callbacks.js
3451
callbacks.d.ts
52+
output_parsers.cjs
3553
output_parsers.js
3654
output_parsers.d.ts
55+
retrievers.cjs
3756
retrievers.js
3857
retrievers.d.ts
58+
index.cjs
3959
index.js
40-
index.d.ts
60+
index.d.ts

0 commit comments

Comments
 (0)