-
Notifications
You must be signed in to change notification settings - Fork 63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
parseSync doesn't load in browser when built with vite and ESM #91
Comments
this is because the package makes use of Node dependencies that aren't available within Vite or the browser. What you can do is pull the package locally and replace them with compatible web api's. |
@rowanfuchs There's no inherent reason why VTT/SRT files cannot be parsed in the browser. Could we therefore leave this bug open, until someone volunteers to do the necessary changes to make it work, please? |
Solution with Vite.
// package.json
{
"dependencies": {
"@esbuild-plugins/node-globals-polyfill": "^0.2.3",
"buffer": "^6.0.3",
"stream-browserify": "^3.0.0",
"subtitle": "^4.2.1"
}
}
// vite.config.js
import { defineConfig } from 'vite'
import NodeGlobalsPolyfillPlugin from '@esbuild-plugins/node-globals-polyfill'
defineConfig({
optimizeDeps: {
esbuildOptions: {
define: { global: 'globalThis' },
plugins: [NodeGlobalsPolyfillPlugin({ buffer: true, process: true })]
}
}
}
// index.js
import { Buffer } from 'buffer'
window.Buffer = Buffer |
prod error:
|
I have a similar issue but for Webpack. Is there any working solution for Webpack? |
Environment:
Reproduction:
1.
Actual result:
Error logs and stacks:
Offending lines:
The text was updated successfully, but these errors were encountered: