esm.sh icon indicating copy to clipboard operation
esm.sh copied to clipboard

`stream-browserify`

Open wojpawlik opened this issue 4 years ago • 7 comments

Thank you for esm.sh, of all the things I tried this gets me the closest to running telegraf on Deno. But not close enough:

~
$ deno --version
deno 1.7.1 (release, x86_64-pc-windows-msvc)
v8 8.9.255.3
typescript 4.1.3

~
$ deno eval 'import "https://esm.sh/[email protected]?dev"'
error: Uncaught SyntaxError: The requested module '/v15/[email protected]/esnext/stream-browserify.development.js' does not provide an export named 'Readable'
import {Readable} from "/v15/[email protected]/esnext/stream-browserify.development.js";
        ~~~~~~~~
    at <anonymous> (https://cdn.esm.sh/v15/[email protected]/esnext/telegraf.development.js:1542:9)

[1] ~
$

telegraf depends on sandwich-stream, which has an .mjs entry which import { Readable } from 'stream'. This is legal:

~
$ node --version
v14.0.0

~
$ node --input-type=module --eval 'import { Readable } from "stream"'

~
$

However, stream-browserify, used by esm.sh to ponyfill stream, doesn't support it. I can open a PR, but only if @goto-bus-stop or another maintainer promises to actually review it.

Otherwise, esm.sh should switch to better maintained ponyfill, perhaps https://deno.land/std/node/stream.ts?

wojpawlik avatar Jan 30 '21 10:01 wojpawlik

If deno provides a stream module itself, the best option would be to exclude stream from the bundle somehow.

Alternatively, esm.sh could use the readable-stream module directly. stream-browserify uses that, but adds support for some very old Node.js APIs for backwards compatibility. That is necessary for browserify which supports many legacy projects that are many years old, but maybe not for esm.sh which (presumably) targets more modern runtimes.

goto-bus-stop avatar Jan 30 '21 10:01 goto-bus-stop

i have a plan to provide all polyfills of nodejs internal module from deno.land/std/node/** to get better deno compatibility, currently i just added the fs polyfill since the std lib doesn't implement all of them. FYI: https://github.com/postui/esm.sh/tree/master/third_party/polyfills

ije avatar Jan 30 '21 11:01 ije

I believe readable stream is getting (kind of) built in Deno support from it's maintainers. Might be something to look at.

shadowtime2000 avatar Feb 05 '21 21:02 shadowtime2000

still happens on v47

➜ deno eval 'import "https://esm.sh/[email protected]?dev"'
Download https://cdn.esm.sh/v47/@types/node/http
Download https://cdn.esm.sh/v47/@types/node/tls
Download https://cdn.esm.sh/v47/@types/node/url
error: Uncaught SyntaxError: The requested module '/v47/[email protected]/deno/stream-browserify.development.js' does not provide an export named 'Readable'
import { Readable } from "/v47/[email protected]/deno/stream-browserify.development.js";
         ~~~~~~~~
    at <anonymous> (https://cdn.esm.sh/v47/[email protected]/deno/sandwich-stream.development.js:3:10)

talentlessguy avatar Sep 06 '21 08:09 talentlessguy

on v50 I see this instead:

error: Uncaught TypeError: Class extends value undefined is not a constructor or null
    var MultipartStream = class extends sandwich_stream_1.default {
                                                          ^
    at ../../../../../tmp/esm-build-e948e7e0c235eccfffa26ffd75dac27c9851089e/node_modules/telegraf/lib/core/network/multipart-stream.js (http://localhost:3333/v50/[email protected]/deno/telegraf.development.js:1034:59)
    at __require2 (http://localhost:3333/v50/[email protected]/deno/telegraf.development.js:31:44)
    at ../../../../../tmp/esm-build-e948e7e0c235eccfffa26ffd75dac27c9851089e/node_modules/telegraf/lib/core/network/client.js (http://localhost:3333/v50/[email protected]/deno/telegraf.development.js:1075:30)
    at __require2 (http://localhost:3333/v50/[email protected]/deno/telegraf.development.js:31:44)
    at ../../../../../tmp/esm-build-e948e7e0c235eccfffa26ffd75dac27c9851089e/node_modules/telegraf/lib/telegram.js (http://localhost:3333/v50/[email protected]/deno/telegraf.development.js:1300:20)
    at __require2 (http://localhost:3333/v50/[email protected]/deno/telegraf.development.js:31:44)
    at ../../../../../tmp/esm-build-e948e7e0c235eccfffa26ffd75dac27c9851089e/node_modules/telegraf/lib/telegraf.js (http://localhost:3333/v50/[email protected]/deno/telegraf.development.js:1764:22)
    at __require2 (http://localhost:3333/v50/[email protected]/deno/telegraf.development.js:31:44)
    at ../../../../../tmp/esm-build-e948e7e0c235eccfffa26ffd75dac27c9851089e/node_modules/telegraf/lib/index.js (http://localhost:3333/v50/[email protected]/deno/telegraf.development.js:2445:22)
    at __require2 (http://localhost:3333/v50/[email protected]/deno/telegraf.development.js:31:44)

talentlessguy avatar Sep 14 '21 07:09 talentlessguy

on v55 it's this:

error: Uncaught TypeError: Class extends value undefined is not a constructor or null
    at https://cdn.esm.sh/v55/[email protected]/deno/telegraf.js:3:22
    at https://cdn.esm.sh/v55/[email protected]/deno/telegraf.js:2:1405
    at https://cdn.esm.sh/v55/[email protected]/deno/telegraf.js:3:559
    at https://cdn.esm.sh/v55/[email protected]/deno/telegraf.js:2:1405
    at https://cdn.esm.sh/v55/[email protected]/deno/telegraf.js:3:4797
    at https://cdn.esm.sh/v55/[email protected]/deno/telegraf.js:2:1405
    at https://cdn.esm.sh/v55/[email protected]/deno/telegraf.js:3:12296
    at https://cdn.esm.sh/v55/[email protected]/deno/telegraf.js:2:1405
    at https://cdn.esm.sh/v55/[email protected]/deno/telegraf.js:3:24524
    at https://cdn.esm.sh/v55/[email protected]/deno/telegraf.js:2:1405

talentlessguy avatar Oct 31 '21 07:10 talentlessguy

same error on v57:

deno eval 'import "https://esm.sh/[email protected]?dev&pin=v57"'
error: Uncaught TypeError: Class extends value undefined is not a constructor or null
    var MultipartStream = class extends sandwich_stream_1.default {
                                                          ^
    at esm-build-3a32e3194a944ce6ceab7e19c7552bc1abaff33e-3acba49b/node_modules/telegraf/lib/core/network/multipart-stream.js (https://cdn.esm.sh/v57/[email protected]/deno/telegraf.development.js:1036:59)
    at __require2 (https://cdn.esm.sh/v57/[email protected]/deno/telegraf.development.js:33:44)
    at esm-build-3a32e3194a944ce6ceab7e19c7552bc1abaff33e-3acba49b/node_modules/telegraf/lib/core/network/client.js (https://cdn.esm.sh/v57/[email protected]/deno/telegraf.development.js:1077:30)
    at __require2 (https://cdn.esm.sh/v57/[email protected]/deno/telegraf.development.js:33:44)
    at esm-build-3a32e3194a944ce6ceab7e19c7552bc1abaff33e-3acba49b/node_modules/telegraf/lib/telegram.js (https://cdn.esm.sh/v57/[email protected]/deno/telegraf.development.js:1302:20)
    at __require2 (https://cdn.esm.sh/v57/[email protected]/deno/telegraf.development.js:33:44)
    at esm-build-3a32e3194a944ce6ceab7e19c7552bc1abaff33e-3acba49b/node_modules/telegraf/lib/telegraf.js (https://cdn.esm.sh/v57/[email protected]/deno/telegraf.development.js:1766:22)
    at __require2 (https://cdn.esm.sh/v57/[email protected]/deno/telegraf.development.js:33:44)
    at esm-build-3a32e3194a944ce6ceab7e19c7552bc1abaff33e-3acba49b/node_modules/telegraf/lib/index.js (https://cdn.esm.sh/v57/[email protected]/deno/telegraf.development.js:2447:22)
    at __require2 (https://cdn.esm.sh/v57/[email protected]/deno/telegraf.development.js:33:44)

talentlessguy avatar Nov 03 '21 21:11 talentlessguy