Skip to content
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

Bam data fetcher issues in development build #991

Open
etowahadams opened this issue Nov 17, 2023 · 0 comments
Open

Bam data fetcher issues in development build #991

etowahadams opened this issue Nov 17, 2023 · 0 comments
Labels
bug🐛 Something isn't working

Comments

@etowahadams
Copy link
Contributor

The BAM data fetcher is broken in the development server, but works production. It stopped working after #977, when major parts of the build were updated.

The Issue
The BAM data fetcher relies on a worker uses gmod/bam which uses Buffer. However, Buffer is undefined in the worker.

Previously, this was solved using this config plugin (in vite.config.js)

const bundleWebWorker = {
    name: 'bundle-web-worker',
    apply: 'serve', // plugin only applied with dev-server
    async transform(_, id) {
        if (/\?worker_file$/.test(id)) {
            // just use esbuild to bundle the worker dependencies
            const bundle = await esbuild.build({
                entryPoints: [id],
                inject: ['./src/alias/buffer-shim.js'],
                format: 'iife',
                bundle: true,
                write: false
            });
            if (bundle.outputFiles.length !== 1) {
                throw new Error('Worker must be a single module.');
            }
            return bundle.outputFiles[0].text;
        }
    }
};

However, this solution no longer works as I now see a Buffer not defined error.

ReferenceError: Buffer is not defined [@gmod_bam.js:8097:39](http://localhost:5173/node_modules/.vite/deps/@gmod_bam.js?v=81069ddd)

Attempts at solving;

I tried upgrading to gmod/bam@1.1.18 to gmod/bam@2.0 since 2.0 has explicit buffer imports. However, this did not solve the problem either. Interestingly, the other workers that use various gmod libraries don't seem to have problems.

@etowahadams etowahadams added the bug🐛 Something isn't working label Nov 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug🐛 Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant