Skip to content

As of @sveltejs/kit version 1.0.13, crypto doesn't seem to be polyfilled during build-time #8655

@mglikesbikes

Description

@mglikesbikes

Describe the bug

Looks like prior to 1.0.13, crypto (the webcrypto global) was polyfilled. Now it doesn't seem to be. (Using adapter-cloudflare-workers if that makes a difference.)

For example: this code will prevent vite build from completing:

if (typeof crypto === 'undefined') throw new Error('this explodes `vite build`')

Reproduction

https://stackblitz.com/edit/sveltejs-kit-template-default-zank98?file=README.md,src%2Froutes%2F%2Bpage.js,package.json&terminal=dev

Steps to repro:

  1. Run npm run build with SK 1.0.12. Note it builds fine.
  2. Run npm i -D @sveltejs/[email protected]
  3. Run npm run build and observe that src/pages.js throws an error because crypto is undefined

Logs

No response

System Info

System:
    OS: macOS 13.1
    CPU: (8) arm64 Apple M1 Pro
    Memory: 1.05 GB / 16.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 18.10.0 - /opt/homebrew/bin/node
    Yarn: 1.22.19 - /opt/homebrew/bin/yarn
    npm: 9.2.0 - /opt/homebrew/bin/npm
  Browsers:
    Chrome: 109.0.5414.87
    Safari: 16.2
  npmPackages:
    @sveltejs/adapter-auto: ^1.0.0 => 1.0.0 
    @sveltejs/adapter-cloudflare-workers: ^1.0.0 => 1.0.0 
    @sveltejs/kit: ^1.0.0 => 1.0.1 
    svelte: ^3.54.0 => 3.55.0 
    vite: ^4.0.0 => 4.0.4```

Severity

blocking an upgrade

Additional Information

Tried to debug this as best I could and it may be related to this PR: #8429

(edited for clarity per findings in comments)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions