deepgram / deepgram-js-sdk

Official JavaScript SDK for Deepgram's automated speech recognition APIs.
https://developers.deepgram.com
MIT License
127 stars 45 forks source link

process is undefined error vite #279

Closed rens-public closed 1 month ago

rens-public commented 1 month ago

This pull request addresses an issue with the Deepgram SDK when used in Vite environments.

Currently, the SDK relies on the process.versions.node property to determine the Node.js version. However, in Vite environments, the process object is not available, leading to errors.

The proposed fix is a check to verify the existence of the process object before accessing process.versions.node. If process is undefined, the NODE_VERSION constant defaults to "unknown".

This change ensures compatibility with Vite and other environments where the process object is not accessible.

lukeocodes commented 1 month ago

I think it would be better to use vite-plugin-env-compatible rather than deliberately break something. Do you want to make a new PR? Or reset this back a few commits and redo it?

Something like this?

  plugins: [
    envCompatible({
      process: true, // This enables the `process` global
    }),
  ],
  define: {
    'process.versions.node': JSON.stringify(process.versions.node),
  }

Or you may want to try this plugin in your own project to see if that resolves it?