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

404 error fetching bindings_wasm_bg.wasm when running rollup on the browser #14609

Closed
7 tasks done
eltaiguer opened this issue Oct 12, 2023 · 5 comments
Closed
7 tasks done
Labels
duplicate This issue or pull request already exists

Comments

@eltaiguer
Copy link

Describe the bug

Hi everyone, not sure if this is the correct place to post this, I already posted on Stack Overflow without luck.

I'm trying to use the package @rollup/browser on my project to generate a dynamic bundle as described here

I know it might sound as if this is not a vite issue, however when running the code I get the following errors:
Screenshot 2023-10-11 at 18 01 32

My first question is, what exactly is the http://localhost:5175/node_modules/.vite/deps/bindings_wasm_bg.wasm file? Do I need to add a specific plugin for this file to exist?

Then there are other problems with the MIME type, which I think I already have a workaround for, and the last error in the screenshot I think it's probably related to the missing file.

Any suggestions about this?

Reproduction

https://github.com/eltaiguer/vite-rollup

Steps to reproduce

Run:
yarn install
yarn dev

Open the console and Click on the "run" button

System Info

System:
    OS: macOS 14.0
    CPU: (10) arm64 Apple M1 Pro
    Memory: 98.56 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 18.14.0 - ~/.nvm/versions/node/v18.14.0/bin/node
    Yarn: 1.22.19 - /opt/homebrew/bin/yarn
    npm: 9.3.1 - ~/.nvm/versions/node/v18.14.0/bin/npm
  Browsers:
    Chrome: 117.0.5938.149
    Safari: 17.0
  npmPackages:
    @vitejs/plugin-react: ^4.0.3 => 4.1.0 
    vite: ^4.4.5 => 4.4.11

Used Package Manager

yarn

Logs

$ tsc && vite build --debug
  vite:config bundled config file loaded in 14.76ms +0ms
  vite:config using resolved config: {
  vite:config   plugins: [
  vite:config     'vite:build-metadata',
  vite:config     'vite:watch-package-data',
  vite:config     'vite:pre-alias',
  vite:config     'alias',
  vite:config     'vite:react-babel',
  vite:config     'vite:react-refresh',
  vite:config     'vite:modulepreload-polyfill',
  vite:config     'vite:resolve',
  vite:config     'vite:html-inline-proxy',
  vite:config     'vite:css',
  vite:config     'vite:esbuild',
  vite:config     'vite:json',
  vite:config     'vite:wasm-helper',
  vite:config     'vite:worker',
  vite:config     'vite:asset',
  vite:config     'vite:wasm-fallback',
  vite:config     'vite:define',
  vite:config     'vite:css-post',
  vite:config     'vite:build-html',
  vite:config     'vite:worker-import-meta-url',
  vite:config     'vite:asset-import-meta-url',
  vite:config     'vite:force-systemjs-wrap-complete',
  vite:config     'commonjs',
  vite:config     'vite:data-uri',
  vite:config     'vite:dynamic-import-vars',
  vite:config     'vite:import-glob',
  vite:config     'vite:build-import-analysis',
  vite:config     'vite:esbuild-transpile',
  vite:config     'vite:terser',
  vite:config     'vite:reporter',
  vite:config     'vite:load-fallback'
  vite:config   ],
  vite:config   optimizeDeps: {
  vite:config     disabled: 'build',
  vite:config     force: undefined,
  vite:config     include: [ 'react', 'react/jsx-dev-runtime', 'react/jsx-runtime' ],
  vite:config     esbuildOptions: { preserveSymlinks: false }
  vite:config   },
  vite:config   build: {
  vite:config     target: [ 'es2020', 'edge88', 'firefox78', 'chrome87', 'safari14' ],
  vite:config     cssTarget: [ 'es2020', 'edge88', 'firefox78', 'chrome87', 'safari14' ],
  vite:config     outDir: 'dist',
  vite:config     assetsDir: 'assets',
  vite:config     assetsInlineLimit: 4096,
  vite:config     cssCodeSplit: true,
  vite:config     sourcemap: false,
  vite:config     rollupOptions: { onwarn: [Function: onwarn] },
  vite:config     minify: 'esbuild',
  vite:config     terserOptions: {},
  vite:config     write: true,
  vite:config     emptyOutDir: null,
  vite:config     copyPublicDir: true,
  vite:config     manifest: false,
  vite:config     lib: false,
  vite:config     ssr: false,
  vite:config     ssrManifest: false,
  vite:config     ssrEmitAssets: false,
  vite:config     reportCompressedSize: true,
  vite:config     chunkSizeWarningLimit: 500,
  vite:config     watch: null,
  vite:config     commonjsOptions: { include: [Array], extensions: [Array] },
  vite:config     dynamicImportVarsOptions: { warnOnError: true, exclude: [Array] },
  vite:config     modulePreload: { polyfill: true },
  vite:config     cssMinify: true
  vite:config   },
  vite:config   esbuild: { jsxDev: false, jsx: 'automatic', jsxImportSource: undefined },
  vite:config   resolve: {
  vite:config     mainFields: [ 'module', 'jsnext:main', 'jsnext' ],
  vite:config     browserField: true,
  vite:config     conditions: [],
  vite:config     extensions: [
  vite:config       '.mjs',  '.js',
  vite:config       '.mts',  '.ts',
  vite:config       '.jsx',  '.tsx',
  vite:config       '.json'
  vite:config     ],
  vite:config     dedupe: [ 'react', 'react-dom' ],
  vite:config     preserveSymlinks: false,
  vite:config     alias: [ [Object], [Object] ]
  vite:config   },
  vite:config   configFile: '/Users/jose/Projects/ikayzo/rollup-test/vite.config.ts',
  vite:config   configFileDependencies: [ '/Users/jose/Projects/ikayzo/rollup-test/vite.config.ts' ],
  vite:config   inlineConfig: {
  vite:config     root: undefined,
  vite:config     base: undefined,
  vite:config     mode: undefined,
  vite:config     configFile: undefined,
  vite:config     logLevel: undefined,
  vite:config     clearScreen: undefined,
  vite:config     optimizeDeps: { force: undefined },
  vite:config     build: {}
  vite:config   },
  vite:config   root: '/Users/jose/Projects/ikayzo/rollup-test',
  vite:config   base: '/',
  vite:config   rawBase: '/',
  vite:config   publicDir: '/Users/jose/Projects/ikayzo/rollup-test/public',
  vite:config   cacheDir: '/Users/jose/Projects/ikayzo/rollup-test/node_modules/.vite',
  vite:config   command: 'build',
  vite:config   mode: 'production',
  vite:config   ssr: {
  vite:config     format: 'esm',
  vite:config     target: 'node',
  vite:config     optimizeDeps: { disabled: true, esbuildOptions: [Object] }
  vite:config   },
  vite:config   isWorker: false,
  vite:config   mainConfig: null,
  vite:config   isProduction: true,
  vite:config   css: undefined,
  vite:config   server: {
  vite:config     preTransformRequests: true,
  vite:config     sourcemapIgnoreList: [Function: isInNodeModules],
  vite:config     middlewareMode: false,
  vite:config     fs: { strict: true, allow: [Array], deny: [Array] }
  vite:config   },
  vite:config   preview: {
  vite:config     port: undefined,
  vite:config     strictPort: undefined,
  vite:config     host: undefined,
  vite:config     https: undefined,
  vite:config     open: undefined,
  vite:config     proxy: undefined,
  vite:config     cors: undefined,
  vite:config     headers: undefined
  vite:config   },
  vite:config   envDir: '/Users/jose/Projects/ikayzo/rollup-test',
  vite:config   env: { BASE_URL: '/', MODE: 'production', DEV: false, PROD: true },
  vite:config   assetsInclude: [Function: assetsInclude],
  vite:config   logger: {
  vite:config     hasWarned: false,
  vite:config     info: [Function: info],
  vite:config     warn: [Function: warn],
  vite:config     warnOnce: [Function: warnOnce],
  vite:config     error: [Function: error],
  vite:config     clearScreen: [Function: clearScreen],
  vite:config     hasErrorLogged: [Function: hasErrorLogged]
  vite:config   },
  vite:config   packageCache: Map(1) {
  vite:config     'fnpd_/Users/jose/Projects/ikayzo/rollup-test' => {
  vite:config       dir: '/Users/jose/Projects/ikayzo/rollup-test',
  vite:config       data: [Object],
  vite:config       hasSideEffects: [Function: hasSideEffects],
  vite:config       webResolvedImports: {},
  vite:config       nodeResolvedImports: {},
  vite:config       setResolvedCache: [Function: setResolvedCache],
  vite:config       getResolvedCache: [Function: getResolvedCache]
  vite:config     },
  vite:config     set: [Function (anonymous)]
  vite:config   },
  vite:config   createResolver: [Function: createResolver],
  vite:config   worker: {
  vite:config     format: 'iife',
  vite:config     plugins: [
  vite:config       'vite:build-metadata',
  vite:config       'vite:watch-package-data',
  vite:config       'vite:pre-alias',
  vite:config       'alias',
  vite:config       'vite:modulepreload-polyfill',
  vite:config       'vite:resolve',
  vite:config       'vite:html-inline-proxy',
  vite:config       'vite:css',
  vite:config       'vite:esbuild',
  vite:config       'vite:json',
  vite:config       'vite:wasm-helper',
  vite:config       'vite:worker',
  vite:config       'vite:asset',
  vite:config       'vite:wasm-fallback',
  vite:config       'vite:define',
  vite:config       'vite:css-post',
  vite:config       'vite:build-html',
  vite:config       'vite:worker-import-meta-url',
  vite:config       'vite:asset-import-meta-url',
  vite:config       'vite:force-systemjs-wrap-complete',
  vite:config       'commonjs',
  vite:config       'vite:data-uri',
  vite:config       'vite:worker-post',
  vite:config       'vite:dynamic-import-vars',
  vite:config       'vite:import-glob',
  vite:config       'vite:build-import-analysis',
  vite:config       'vite:esbuild-transpile',
  vite:config       'vite:terser',
  vite:config       'vite:load-fallback'
  vite:config     ],
  vite:config     rollupOptions: {},
  vite:config     getSortedPlugins: [Function: getSortedPlugins],
  vite:config     getSortedPluginHooks: [Function: getSortedPluginHooks]
  vite:config   },
  vite:config   appType: 'spa',
  vite:config   experimental: { importGlobRestoreExtension: false, hmrPartialAccept: false },
  vite:config   getSortedPlugins: [Function: getSortedPlugins],
  vite:config   getSortedPluginHooks: [Function: getSortedPluginHooks]
  vite:config } +15ms
vite v4.4.11 building for production...
  vite:esbuild 12.54ms tsconfck init /Users/jose/Projects/ikayzo/rollup-test +0ms
transforming (1) index.html  vite:resolve 1.96ms bindings_wasm_bg.wasm -> /Users/jose/Projects/ikayzo/rollup-test/node_modules/@rollup/browser/dist/es/bindings_wasm_bg.wasm +0ms
✓ 35 modules transformed.
dist/index.html                                 0.46 kB │ gzip:   0.30 kB
dist/assets/react-35ef61ed.svg                  4.13 kB │ gzip:   2.14 kB
dist/assets/bindings_wasm_bg-48cddf5d.wasm  5,452.66 kB
dist/assets/index-d526a0c5.css                  1.42 kB │ gzip:   0.74 kB
dist/assets/index-334d7831.js                 459.30 kB │ gzip: 137.60 kB
✓ built in 844ms
✨  Done in 2.24s.

Validations

@eltaiguer
Copy link
Author

Update about this, I notice that when I run yarn build I see a bindings_was_bg.wasm file under the assets folder, however, I have no idea how is that file is being expected under node_modules

@curran
Copy link
Contributor

curran commented Oct 16, 2023

I'm experiencing the same issue.

Here's a minimal reproduction repo: https://github.com/curran/rollup-v4-browser-vite-demo

In that repo:

  • Running npm run dev fails
  • Running npm run build does produce the WASM asset
  • Running npm run preview works! The code runs and uses the correct WASM asset

This leads me to believe it is an issue isolated to the dev server setup.

Also, I was encountering a related issue around MIME types for the WASM asset, which I solved here curran/rollup-v4-browser-vite-demo#2 , but I'm not sure if this is a symptom of the underlying problem which is that Vite does not serve the file in dev at all, so of course the MIME type will be incorredt.

Here's a StackOverflow post about the same/similar error https://stackoverflow.com/questions/77276441/vite-react-wasm-errors-when-running-rollup-browser-side

I'm currently trying to figure out what to do for migrating to v4 to support the browser build of Rollup in a Vite-based app. Sharing my research so far here.

I reviewed the migration guide https://rollupjs.org/migration/ but nothing is mentioned there about WASM for the browser build. I also see that in https://github.com/rollup/rollup/blob/master/CHANGELOG.md#general-changes There is this hint:

The browser build now relies on a WASM artifact that needs to be provided as well (#5073)

I'm currently trying to decipher rollup/rollup#5073 to find out if there's anything we can do outside of Vite itself to make it work.

To summarize the issue, I see two possibilities:

  • The Rollup browser build may not be using the right path for the WASM asset when running Vite's npm run dev.
  • Vite may not be serving the file at the right path when running npm run dev.

Looking forward to solving this issue! Any clues would be greatly appreciated.

@sadn1ck
Copy link

sadn1ck commented Oct 17, 2023

what exactly is the http://localhost:5175/node_modules/.vite/deps/bindings_wasm_bg.wasm

That's how rollup bundles in the browser, using WASM: https://github.com/rollup/rollup/blob/master/browser/package.json#L23

To get it to run, add "@rollup/browser" to optimizeDeps.exclude, which prevents the prebundling and messing up of paths to the .wasm file.

See: https://stackblitz.com/edit/github-hqaxdk?file=vite.config.ts

@curran
Copy link
Contributor

curran commented Oct 17, 2023

Amazing! Thank you so much! That works for me.

I've included the fix here https://github.com/curran/rollup-v4-browser-vite-demo/blob/main

@sapphi-red
Copy link
Member

Duplicate of #8427

@sapphi-red sapphi-red marked this as a duplicate of #8427 Oct 18, 2023
@sapphi-red sapphi-red closed this as not planned Won't fix, can't repro, duplicate, stale Oct 18, 2023
@sapphi-red sapphi-red added duplicate This issue or pull request already exists and removed pending triage labels Oct 18, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Nov 2, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

4 participants