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

vite dev doesn't copy assets to node_modules/.vite/deps via new URL() support in worker scripts #10761

Closed
7 tasks done
schickling opened this issue Nov 2, 2022 · 5 comments
Closed
7 tasks done
Labels
duplicate This issue or pull request already exists

Comments

@schickling
Copy link
Contributor

Describe the bug

vite dev doesn't copy assets to node_modules/.vite/deps via new URL() support in worker scripts

Manually copying the missing assets to node_modules/.vite/deps seems to fix the problem as a workaround.

Reproduction

https://github.com/schickling-test/2022-nov-vite-worker-dev-repro

Steps to reproduce

Unfortunately due to some Stackblitz WASM limitations, it doesn't work on Stackblitz yet.

Setup

git clone git@github.com:schickling-test/2022-nov-vite-worker-dev-repro.git
2022-nov-vite-worker-dev-repro
npm install

Repro bug: dev not working

npm run dev
# dev console should now show WASM errors and the network monitor should show 404s

CleanShot 2022-11-02 at 10 45 43@2x

Repro workaround: dev working

npm run dev
npm run fix-dev # run in another terminal
# things should work now

CleanShot 2022-11-02 at 10 47 17@2x

Repro prod build working

npm run build
npm run preview # uses netlify cli to use the needed HTTP headers
# things should work now

CleanShot 2022-11-02 at 10 37 14@2x

System Info

System:
    OS: macOS 13.0
    CPU: (10) arm64 Apple M1 Max
    Memory: 47.81 MB / 32.00 GB
    Shell: 3.4.1 - /Users/schickling/.nix-profile/bin/fish
  Binaries:
    Node: 16.16.0 - ~/.nix-profile/bin/node
    Yarn: 1.22.18 - ~/.nix-profile/bin/yarn
    npm: 8.11.0 - ~/.nix-profile/bin/npm
  Browsers:
    Chrome: 107.0.5304.87
    Chrome Canary: 109.0.5396.0
    Firefox: 100.0
    Safari: 16.1
  npmPackages:
    vite: ^3.2.2 => 3.2.2

Used Package Manager

npm

Logs

No response

Validations

@schickling
Copy link
Contributor Author

Possibly related to #8427 but the mentioned optimizeDeps.exclude workaround didn't work for me.

@sapphi-red
Copy link
Member

@schickling optimizeDeps.exclude did work for me. Would you try it again just in case?

import { defineConfig } from 'vite'

// https://vitejs.dev/config/
export default defineConfig({
  server: {
    port: 8083,
  },
  build: {
    sourcemap: true,
    target: ['es2020'],
  },
  optimizeDeps: {
    esbuildOptions: { target: 'es2020' },
    exclude: ['sqlite-wasm-esm']
  },
  plugins: [
    // Needed to enable OPFS
    {
      name: 'configure-response-headers',
      configureServer: (server) => {
        server.middlewares.use((_req, res, next) => {
          res.setHeader('Cross-Origin-Opener-Policy', 'same-origin')
          res.setHeader('Cross-Origin-Embedder-Policy', 'require-corp')
          next()
        })
      },
    },
  ],
})

@sapphi-red sapphi-red added cannot reproduce The bug cannot be reproduced and removed cannot reproduce The bug cannot be reproduced labels Nov 29, 2022
@schickling
Copy link
Contributor Author

Thanks a lot for your comment, I'll give the exclude option another try.

Given I have control over the sqlite-wasm-esm package, are there some patterns that can cause this? So put differently, what could I change in the sqlite-wasm-esm package so this problem might be resolved?

@sapphi-red
Copy link
Member

sapphi-red commented Dec 2, 2022

I guess replacing const wasmUrl = new URL('sqlite3.wasm', import.meta.url).href with import wasmUrl from 'sqlite3.wasm?url' would work for Vite.
But that will break other bundlers and nodejs.

@schickling
Copy link
Contributor Author

Thanks a lot for your comment, I'll give the exclude option another try.

Using exclude: ['sqlite-wasm-esm'] seems to indeed work now as a workaround. Closing as duplicate of #8427.

Thanks for your help @sapphi-red

@schickling schickling closed this as not planned Won't fix, can't repro, duplicate, stale Dec 3, 2022
@sapphi-red sapphi-red added duplicate This issue or pull request already exists and removed pending triage labels Dec 3, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Dec 18, 2022
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

2 participants