twilio / twilio-voice.js

Twilio's JavaScript Voice SDK
Other
50 stars 53 forks source link

[BUG] #124

Closed DosCervezas closed 1 year ago

DosCervezas commented 1 year ago

I just added the @twilio/voice-sdk with npm install and if I try to build all my js libraries with esbuild I get the error 'The package "events" wasn't found on the file system but is built into node' package.json:

{ "name": "app", "private": "true", "dependencies": { "@twilio/voice-sdk": "^2.1.2", "esbuild": "^0.15.8" }, "scripts": { "build": "esbuild app/javascript/. --bundle --sourcemap --outdir=app/assets/builds --public-path=assets", "build:css": "sass ./app/assets/stylesheets/application.bootstrap.scss:./app/assets/builds/application.css --no-source-map --load-path=node_modules" } }

I could add the platform=node flag to the esbuild to build it successfully but I am running an Ruby on Rails App and therefore are all JS Modules for the frontend itself -> will be shipped to the browser. I am sure this flag is not a good security option. But the example uses this library in the frontend and delivers it.. but to make the example simple just the minified version is used... https://github.com/TwilioDevEd/voice-javascript-sdk-quickstart-ruby But @twilio/voice-sdk recommend using npm.. so i want to use it (its lesser work for myself)

Expected behavior:

I can build with esbuild all my js frontend libraries without some extra twilio workaround stuff

Actual behavior: Log:

20:31:02 js.1 | $ esbuild app/javascript/. --bundle --sourcemap --outdir=app/assets/builds --public-path=assets --watch 20:31:02 css.1 | $ sass ./app/assets/stylesheets/application.bootstrap.scss:./app/assets/builds/application.css --no-source-map --load-path=node_modules --watch 20:31:02 js.1 | ✘ [ERROR] Could not resolve "events" 20:31:02 js.1 | 20:31:02 js.1 | node_modules/@twilio/voice-sdk/es5/twilio/preflight/preflight.js:69:23: 20:31:02 js.1 | 69 │ var events_1 = require("events"); 20:31:02 js.1 | ╵ ~~~~ 20:31:02 js.1 | 20:31:02 js.1 | The package "events" wasn't found on the file system but is built into node. Are you trying to bundle for node? You can use "--platform=node" to do that, which will remove this error. 20:31:02 js.1 | 20:31:02 js.1 | ✘ [ERROR] Could not resolve "events" 20:31:02 js.1 | 20:31:02 js.1 | node_modules/@twilio/voice-sdk/es5/twilio/call.js:33:23: 20:31:02 js.1 | 33 │ var events_1 = require("events"); 20:31:02 js.1 | ╵ ~~~~ 20:31:02 js.1 | 20:31:02 js.1 | The package "events" wasn't found on the file system but is built into node. Are you trying to bundle for node? You can use "--platform=node" to do that, which will remove this error. 20:31:02 js.1 | 20:31:02 js.1 | ✘ [ERROR] Could not resolve "events" 20:31:02 js.1 | 20:31:02 js.1 | node_modules/@twilio/voice-sdk/es5/twilio/device.js:69:23: 20:31:02 js.1 | 69 │ var events_1 = require("events"); 20:31:02 js.1 | ╵ ~~~~ 20:31:02 js.1 | 20:31:02 js.1 | The package "events" wasn't found on the file system but is built into node. Are you trying to bundle for node? You can use "--platform=node" to do that, which will remove this error. 20:31:02 js.1 | 20:31:02 js.1 | ✘ [ERROR] Could not resolve "events" 20:31:02 js.1 | 20:31:02 js.1 | node_modules/@twilio/voice-sdk/es5/twilio/eventpublisher.js:9:27: 20:31:02 js.1 | 9 │ var EventEmitter = require('events').EventEmitter; 20:31:02 js.1 | ╵ ~~~~ 20:31:02 js.1 | 20:31:02 js.1 | The package "events" wasn't found on the file system but is built into node. Are you trying to bundle for node? You can use "--platform=node" to do that, which will remove this error. 20:31:02 js.1 | 20:31:02 js.1 | ✘ [ERROR] Could not resolve "events" 20:31:02 js.1 | 20:31:02 js.1 | node_modules/@twilio/voice-sdk/es5/twilio/audiohelper.js:20:23: 20:31:02 js.1 | 20 │ var events_1 = require("events"); 20:31:02 js.1 | ╵ ~~~~ 20:31:02 js.1 | 20:31:02 js.1 | The package "events" wasn't found on the file system but is built into node. Are you trying to bundle for node? You can use "--platform=node" to do that, which will remove this error. 20:31:02 js.1 | 20:31:02 js.1 | ✘ [ERROR] Could not resolve "events" 20:31:02 js.1 | 20:31:02 js.1 | node_modules/@twilio/voice-sdk/es5/twilio/statsMonitor.js:39:23: 20:31:02 js.1 | 39 │ var events_1 = require("events"); 20:31:02 js.1 | ╵ ~~~~ 20:31:02 js.1 | 20:31:02 js.1 | The package "events" wasn't found on the file system but is built into node. Are you trying to bundle for node? You can use "--platform=node" to do that, which will remove this error. 20:31:02 js.1 | 20:31:02 js.1 | 6 of 20 errors shown (disable the message limit with --log-limit=0) 20:31:02 js.1 | [watch] build finished, watching for changes... 20:31:05 css.1 | Compiled app/assets/stylesheets/application.bootstrap.scss to app/assets/builds/application.css. 20:31:05 css.1 | Sass is watching for changes. Press Ctrl-C to stop. 20:31:05 css.1 |

TODO

Software versions:

mhuynh5757 commented 1 year ago

Hi @DosCervezas, thanks for bringing this to our attention. We've filed an internal ticket to track this. In the meantime, could you try this workaround?

NPM provides "installation aliasing" such that you can install a package under an alias. The very popular eventemitter3 package (https://www.npmjs.com/package/eventemitter3) should have the same signature as the built-in Node.js event module. Installing eventemitter3 as an alias for event could work, and can be done like so

npm i event@npm:eventemitter3

Check the npm docs to see if it suits your use-case first: https://docs.npmjs.com/cli/v8/commands/npm-install

mhuynh5757 commented 1 year ago

(Also please in the future have a title for future Issue Requests)

DosCervezas commented 1 year ago

ohh fail sorry mybad, ofc I will title next time, first issue 😉

I already added the twilio.min.js prebuild from your github repository and It works like a charm. If you fixed this bug I will switch back to the npm dependency!

Thanks for your fast reply! 😁