question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`ssrLoadModule` does not load nested dependency

See original GitHub issue

Describe the bug

Original issue discovered: https://github.com/vitejs/vite/discussions/3464#discussioncomment-807918

I have a vite plugin that make use of the ssr argument in resolveId hook. The main purpose of the plugin is to replace @shopify/polyfills/fetch with @shopify/polyfills/fetch.node when its on the server and @shopify/polyfills/fetch.browser when it is on the client.

This plugins work on the client side, but break when ssrLoadModule is use to load the server entry point.

Some investigations

I have tired to replace @shopify/polyfills/fetch with a random virtual module (ie. virtual:fetch-polyfill) and that work.

Reproduction

Use the branch https://github.com/michenly/app-proving-ground/tree/vite-ssr-dep

Case 1: client side only with a index file

  • Run yarn dev
  • See the application working with a list displayed in the browser.

Case 2: ssr using vite middleware and ssrLoadModule

  • Run yarn run ssr
  • See the application fail with the following error Screen Shot 2021-05-31 at 5 04 50 PM

Case 3: same as 2, but using virtual module

  • Change @shopify/polyfills/fetch to virtual:fetch-polyfill in both the plugin and the client import in GraphQL.tsx
  • Run yarn run ssr
  • See the following error which mean the module is broken. But it is loaded on server side. Screen Shot 2021-05-31 at 5 04 12 PM

System Info

Output of npx envinfo --system --npmPackages vite,@vitejs/plugin-vue --binaries --browsers:

System:
    OS: macOS 11.3.1
    CPU: (8) x64 Intel(R) Core(TM) i7-8559U CPU @ 2.70GHz
    Memory: 338.92 MB / 16.00 GB
    Shell: 4.4.23 - /usr/local/bin/bash
  Binaries:
    Node: 16.1.0 - /usr/local/bin/node
    Yarn: 1.22.10 - /usr/local/bin/yarn
    npm: 7.11.2 - /usr/local/bin/npm
    Watchman: 4.9.0 - /usr/local/bin/watchman
  Browsers:
    Chrome: 90.0.4430.212
    Firefox: 72.0.2
    Safari: 14.1
  npmPackages:
    vite: ^2.2.3 => 2.2.3

Used package manager: yarn


Before submitting the issue, please make sure you do the following

  • Read the Contributing Guidelines.
  • Read the docs.
  • Check that there isn’t already an issue that reports the same bug to avoid creating a duplicate.
  • Provide a description in this issue that describes the bug.
  • Make sure this is a Vite issue and not a framework-specific issue. For example, if it’s a Vue SFC related bug, it should likely be reported to https://github.com/vuejs/vue-next instead.
  • Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
aleclarsoncommented, Jul 22, 2021

It depends. To support the exports field, Vite uses the resolve.exports package, which has a conditions option for deciding which keywords to look for. Note that Vite SSR does not use that package, but this will change with #3951.

0reactions
bluwycommented, Mar 14, 2022

I think the correct solution here is to use exports to load between node and browser, or alias as a workaround for the package. Closing as it seems to be working as intended.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Maven nested dependency is not accessible - Stack Overflow
My understanding about Maven dependencies is that, since I have declared the dependency in Parent POM, it should get inherited in the child...
Read more >
Server-Side Rendering - Vite
Produce a client build as normal;; Produce an SSR build, which can be directly loaded via import() so that we don't have to...
Read more >
require is not defined nuxt | The AI Search Engine You Control
It's a common error when you start a Nuxt project ;-). The Choices.js lib is available only for client-side! So Nuxt tried to...
Read more >
Structuremap ioc nested container / per request
Is there an extension point where we can create a new/nested ioc ... Ok, but then auto-resolving dependencies in services won't work.
Read more >
Recommended - SlideShare
Glob Import Caveats Note that: This is a Vite-only feature and is not. warning [ES Module Integration Proposal for ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found