speechmatics / speechmatics-js-sdk

Javascript and Typescript SDK for Speechmatics
MIT License
40 stars 7 forks source link

Incompatibility with babel library #62

Closed hakonbjork1 closed 2 weeks ago

hakonbjork1 commented 1 month ago

Describe the bug When using speechmatics together with packages depending on @babel/plugin-transform-parameters, the project fails to compile and build because of the following SyntaxError:

SyntaxError: C:\...\cra-speechmatics-test\node_modules\speechmatics\dist\utils\errors.js: When using '@babel/plugin-transform-parameters', it's not possible to compile `super()` in an arrow function with default or rest parameters without compiling classes.
Please add '@babel/plugin-transform-classes' to your Babel configuration.
  49 |   constructor(errorResponse) {
  50 |     var __super = (...args) => {
> 51 |       super(...args);
     |       ^^^^^^^^^^^^^^
  52 |     };
  53 |     const parse = ErrorResponseSchema.safeParse(errorResponse);
  54 |     if (parse.success) {

When using Create React App, this happens right after installing speechmatics and attempting to build.

To Reproduce Steps to reproduce the behavior:

  1. Use Create React App to create a new project: npx create-react-app my-app
  2. Install speechmatics: npm install speechmatics
  3. Make sure speechmatics is included in the code by adding the following line to index.js: import "speechmatics"
  4. Attempt to build the project: npm run build
  5. See the error appear

Expected behavior A project using speechmatics and packages depending on @babel/plugin-transform-parameters should be able to build without problem.

Screenshots Screenshot of the error: image

Desktop (please complete the following information):

mnemitz commented 4 weeks ago

Hi, thanks for flagging this. Sorry to hear that the SDK isn't working with this Babel plugin.

There are a number of issues with the build of the current SDK package, the main one being that we're only outputting CommonJS, and using a fairly basic ESBuild configuration for the compilation.

We are currently working on an overhaul of the SDK which will split the various components into standalone packages built as both ES Modules and CommonJS for Node. We're aiming to have this ready in the next few days.

When using Create React App, their docs seem to suggest ES Modules are preferred, so hopefully this will solve your use case. Happy to keep this issue open until it's resolved.

mnemitz commented 2 weeks ago

Hi @hakonbjork1 . Just wanted to follow up and let you know that the new batch and real-time packages are now available on NPM:

https://www.npmjs.com/package/@speechmatics/batch-client https://www.npmjs.com/package/@speechmatics/real-time-client

Both these packages export ESM and CJS, so it should integrate better with your babel plugin. I'm going to close this issue, but feel free to reopen or make a new issue if you encounter any further problems.

hakonbjork1 commented 1 week ago

Hi! Thanks for dealing with this and letting me know🙌