subtitle.js icon indicating copy to clipboard operation
subtitle.js copied to clipboard

parseSync doesn't load in browser when built with vite and ESM

Open benbucksch opened this issue 11 months ago • 4 comments

Environment:

  • vite 4.3.9
  • Svelte (without SvelteKit) 3.58.0
  • @sveltejs/vite-plugin-svelte 2.4.1

Reproduction: 1.

import { parseSync } from 'subtitle';
const nodes = parseSync(fileContents);
  1. Run app in browser

Actual result:

  • App doesn't load at all
  • Errors on browser error console (see below)

Error logs and stacks:

Uncaught (in promise) ReferenceError: process is not defined
    js _stream_writable.js:57
    __require2 chunk-TFWDKVI3.js:18
    js readable-browser.js:4
    __require2 chunk-TFWDKVI3.js:18
    js index.js:3
    __require2 chunk-TFWDKVI3.js:18
    js index.js:5
    __require2 chunk-TFWDKVI3.js:18
    <anonymous> subtitle.js:15
Uncaught (in promise) ReferenceError: global is not defined
    at node_modules/readable-stream/lib/_stream_readable.js (_stream_readable.js:56:21)
    at __require2 (chunk-TFWDKVI3.js?v=950aa587:18:50)
    at node_modules/readable-stream/readable-browser.js (readable-browser.js:1:28)
    at __require2 (chunk-TFWDKVI3.js?v=950aa587:18:50)
    at node_modules/duplexer2/index.js (index.js:3:14)
    at __require2 (chunk-TFWDKVI3.js?v=950aa587:18:50)
    at node_modules/multipipe/index.js (index.js:5:18)
    at __require2 (chunk-TFWDKVI3.js?v=950aa587:18:50)
    at index.js:15:1

Offending lines:

var asyncWrite = !process.browser && ["v0.10", "v0.9."].indexOf(process.version.slice(0, 5)) > -1 ? setImmediate : pna.nextTick;
var import_multipipe = __toESM(require_multipipe());

benbucksch avatar Jul 12 '23 15:07 benbucksch