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.

Support sveltekit (vite)

See original GitHub issue

Intended outcome: Apollo Client to work with sveltekit

Actual outcome: I’m attempting to use Apollo Client with sveltekit, I can run the dev server just fine, but when I build the project and run it using node I get an error

Directory import '/Users/.../node_modules/@apollo/client/core' is not supported resolving ES modules imported from /Users/.../.svelte-kit/output/server/app.js
Did you mean to import @apollo/client/core/core.cjs.js?

Now if I instead import the Apollo Client from @apollo/client instead of @apollo/client/core I don’t get this issue, I suspect because of this line in the Apollo Client package.json "module": "./index.js" (but I’m no expert)

However I cannot import the client directly from @apollo/client because it is dependent upon the react module, and since sveltekit does server side rendering the react package explodes in a node environment. here’s a related issue discussing this in the Vite repo (sveltekit uses Vite internally)

I guess my best bet would be to attempt to instruct the build process to replace @apollo/client/core with @apollo/client/core/index.js at build time, which I will attempt to look into as a fix.

Are there any other suggested approaches fix this issue?

How to reproduce the issue: Download the sveltekit starter npm init svelte@next my-app Include the Apollo Client package Attempt to build I created a reproducible repo here Versions

System: OS: macOS 11.3 Binaries: Node: 16.0.0 - /usr/local/bin/node Yarn: 1.22.10 - ~/Documents/eddystone/node_modules/.bin/yarn npm: 7.10.0 - /usr/local/bin/npm Browsers: Chrome: 90.0.4430.212 Safari: 14.1 npmPackages: @apollo/client: ^3.3.18 => 3.3.18

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:30
  • Comments:43 (7 by maintainers)

github_iconTop GitHub Comments

7reactions
cudrcommented, Jul 6, 2021

Hi, @benjamn! I’ve checked @apollo/client@beta and have the same problem. Thinking this issue is related to https://github.com/sveltejs/kit/issues/612. If we need an import scope submodule, we need to add some export information, like https://github.com/ReactiveX/rxjs/pull/6192/files do.

In my case, adding these lines to @apollo/client package.json solved the problem:

"exports": {
    ".": {
      "node": "./main.cjs.js",
      "default": "./index.js"
    },
    "./cache": {
      "node": "./cache/cache.cjs.js",
      "default": "./cache/index.js"
    },
    "./core": {
      "node": "./core/core.cjs.js",
      "default": "./core/index.js"
    },
    "./link/schema": {
      "node": "./link/schema/schema.cjs.js",
      "default": "./link/schema/index.js"
    },
    "./link/http": {
      "node": "./link/http/http.cjs.js",
      "default": "./link/http/index.js"
    }
  },

What is your opinion on this?

6reactions
benmccanncommented, Feb 4, 2022

Thanks for all your help! And yes I can confirm it’s working now. Here’s is a fork of the repo posted above where it’s working: https://github.com/benmccann/sveltekit-apollo-build-bug/tree/working-version

All that is needed is an updated version of @apollo/client and then change the import from @apollo/client/core to @apollo/client/core/index.js

What do you think about a PR to add an exports map to support importing from @apollo/client/core as a slightly nicer API? Or would that be too breaking of a change?

Read more comments on GitHub >

github_iconTop Results From Across the Web

FAQ • SvelteKit
Vite's SSR support has become fairly stable since Vite 2.7. Most issues related to including a library are due to incorrect packaging.
Read more >
add support for new SvelteKit and Vite integration #324 - GitHub
When I do the install routine using npm, then I get error - Cannot find module '@vite-pwa/sveltekit' or its corresponding type declarations.ts( ...
Read more >
SvelteKit | Frameworks - Vite PWA - Netlify
For Type declarations , Prompt for update and Periodic SW Updates go to Svelte entry. TIP. You should remove all references to SvelteKit...
Read more >
SvelteKit vite configuration HELP : r/sveltejs - Reddit
SvelteKit vite configuration HELP. So i keep getting this. The request url "C:\Users\me\GitHub\project\static\croissant.svelte" is outside ...
Read more >
vitest-svelte-kit - npm
It does not actually run SvelteKit, but rather configures Vite in a way similar to how SvelteKit would do so. Svelte File Support....
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 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