starmorph / langchain-js-quickstart

A node.js single file app with a basic langchain script that uses OpenAI to generate a react component code snippet.
84 stars 25 forks source link

Headers is not defined. #4

Open caranicas opened 1 year ago

caranicas commented 1 year ago

I cloned the repo, installed and tried to run the dev command but I got the following error

langchain-js-quickstart> npm run dev

> dev
> ts-node --esm ./src/app.ts

ReferenceError: Headers is not defined
    at createRequest ([PATH]/langchain-js-quickstart/node_modules/langchain/src/util/axios-fetch-adapter.js:273:19)
    at fetchAdapter ([PATH]/langchain-js-quickstart/node_modules/langchain/src/util/axios-fetch-adapter.js:196:19)
    at dispatchRequest ([PATH]\langchain-js-quickstart\node_modules\axios\lib\core\dispatchRequest.js:58:10)
    at Axios.request ([PATH]\langchain-js-quickstart\node_modules\axios\lib\core\Axios.js:108:15)
    at Function.wrap [as request] ([PATH]\langchain-js-quickstart\node_modules\axios\lib\helpers\bind.js:9:15)
    at [PATH]\langchain-js-quickstart\node_modules\openai\dist\common.js:149:22
    at [PATH]\langchain-js-quickstart\node_modules\openai\dist\api.js:1738:133
mattchw commented 1 year ago

According to the LangChain Documentation, Node.js 16 is not supported. If you wanna make fetch avaiable, you can:

  1. run with node option NODE_OPTIONS='--experimental-fetch' ts-node --esm ./src/app.ts
  2. install node-fetch