jddev273 / streamed-chatgpt-api

A node module for streaming API responses from the ChatGPT APi.
MIT License
30 stars 6 forks source link

Error with require of node-fetch #8

Open rubyshines opened 1 year ago

rubyshines commented 1 year ago

I am getting the following error when I run the demo app. I have an implementation that cannot use import statements.

internal/modules/cjs/loader.js:1131
      throw new ERR_REQUIRE_ESM(filename, parentPath, packageJsonPath);
      ^

Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /Users/me/Downloads/simple-chatgpt-chat-streaming-demo-master/node_modules/node-fetch/src/index.js
require() of ES modules is not supported.
require() of /Users/me/Downloads/simple-chatgpt-chat-streaming-demo-master/node_modules/node-fetch/src/index.js from /Users/me/Downloads/simple-chatgpt-chat-streaming-demo-master/node_modules/streamed-chatgpt-api/index.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
Instead rename /Users/me/Downloads/simple-chatgpt-chat-streaming-demo-master/node_modules/node-fetch/src/index.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /Users/me/Downloads/simple-chatgpt-chat-streaming-demo-master/node_modules/node-fetch/package.json.

    at new NodeError (internal/errors.js:322:7)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1131:13)
    at Module.load (internal/modules/cjs/loader.js:979:32)
    at Function.Module._load (internal/modules/cjs/loader.js:819:12)
    at Module.require (internal/modules/cjs/loader.js:1003:19)
    at require (internal/modules/cjs/helpers.js:107:18)
    at Object.<anonymous> (/Users/me/Downloads/simple-chatgpt-chat-streaming-demo-master/node_modules/streamed-chatgpt-api/index.js:1:35)
    at Module._compile (internal/modules/cjs/loader.js:1114:14)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1143:10)
    at Module.load (internal/modules/cjs/loader.js:979:32) {
  code: 'ERR_REQUIRE_ESM'
}

Process finished with exit code 1