AxisCommunications / media-stream-library-js

JavaScript library to handle media streams on the command line (Node.js) and in the browser.
MIT License
295 stars 101 forks source link

Cannot use versions >v11.2.0 in a pure ESM project #990

Open vetlevo opened 1 month ago

vetlevo commented 1 month ago

Hello! We're using the media-stream-library in a NodeJS project that is configured to only allow 'import' syntax. This still allows importing CommonJS modules, and we haven't had any issues with this in the past.

However, if we upgrade the media-stream-library beyond v11.2.0, we get the following error at runtime (This is with v13.1.1):

node_modules/media-stream-library/dist/node.mjs:12
  throw Error('Dynamic require of "' + x + '" is not supported');
        ^
Error: Dynamic require of "tty" is not supported
    at file:/node_modules/media-stream-library/dist/node.mjs:12:9
    at ../node_modules/debug/src/node.js (file:/node_modules/media-stream-library/dist/node.mjs:1129:15)
    at __require2 (file:/node_modules/media-stream-library/dist/node.mjs:15:50)
    at ../node_modules/debug/src/index.js (file:/node_modules/media-stream-library/dist/node.mjs:1306:24)
    at __require2 (file:/node_modules/media-stream-library/dist/node.mjs:15:50)
    at file:/node_modules/media-stream-library/dist/node.mjs:2020:28
    at ModuleJob.run (node:internal/modules/esm/module_job:218:25)
    at async ModuleLoader.import (node:internal/modules/esm/loader:329:24)
    at async loadESM (node:internal/process/esm_loader:28:7)
    at async handleMainPromise (node:internal/modules/run_main:113:12)

Node.js v20.11.0

From what I can tell, there seems to be require syntax in an mjs file that causes the issue.

Any thoughts?

vetlevo commented 1 month ago

For now, our fix is to remove the constraints in our project to be an ES module. This works for us as we currently don't have other dependencies in this project that have the same constraints.

steabert commented 1 month ago

Yes, this is a head-ache for us too, I'll have to have another look at this. I think it might be difficult since we ourselves depend on things that only are CommonJS. So we might by lying to Node.js by saying it's .mjs.

steabert commented 1 month ago

It looks like it's the debug package, we should probably replace it with a simple utility or something like tslog, because from the comments on their repo it doesn't seem like they will give up CommonJS any time soon.