Skip to content

Vite ssr throws when npm package exports a promise #8673

@gzzhanghao

Description

@gzzhanghao

Describe the bug

vite.ssrLoadModule will stuck when importing a npm package which exports a unresolved thenable (like unenv/runtime/mock/proxy). And it throws when the npm package exports a real promise:

3:16:09 PM [vite] Error when evaluating SSR module /src/main.js:
TypeError: Method Promise.prototype.then called on incompatible receiver [object Module]
    at Proxy.then (<anonymous>)
node:internal/process/promises:279
            triggerUncaughtException(err, true /* fromPromise */);
            ^

TypeError: Method Promise.prototype.then called on incompatible receiver [object Module]
    at Proxy.then (<anonymous>)

Reproduction

https://github.com/gzzhanghao/vue-promise-issue

System Info

Binaries:
    Node: 16.15.1
    Yarn: 1.22.17
    npm: 8.11.0
  npmPackages:
    vite: ^2.9.12 => 2.9.12

Used Package Manager

yarn

Logs

No response

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    feat: ssrp3-minor-bugAn edge case that only affects very specific usage (priority)wontfixThis will not be worked on

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions