svelte-apollo icon indicating copy to clipboard operation
svelte-apollo copied to clipboard

Error [ERR_UNSUPPORTED_DIR_IMPORT]

Open happysalada opened this issue 3 years ago • 3 comments

Hi, thank you for the project!

Upon adding this to an almost brand-new svelte kit project with adapter static, I get the following error

Error [ERR_UNSUPPORTED_DIR_IMPORT]: Directory import '/Users/raphael/dev/nyt/node_modules/.pnpm/svelte-apo
[email protected]_0797cffbf2a19052134926e8d6fad18a/node_modules/@apollo/client/core' is not supported resolving ES
 modules imported from /Users/raphael/dev/nyt/node_modules/.pnpm/[email protected]_0797cffbf2a1905213492
6e8d6fad18a/node_modules/svelte-apollo/dist/svelte-apollo.js
Did you mean to import @[email protected][email protected]/node_modules/@apollo/client/core/core.cjs?
    at new NodeError (internal/errors.js:322:7)
    at finalizeResolution (internal/modules/esm/resolve.js:314:17)
    at moduleResolve (internal/modules/esm/resolve.js:776:10)
    at Loader.defaultResolve [as _resolve] (internal/modules/esm/resolve.js:887:11)
    at Loader.resolve (internal/modules/esm/loader.js:89:40)
    at Loader.getModuleJob (internal/modules/esm/loader.js:242:28)
    at ModuleWrap.<anonymous> (internal/modules/esm/module_job.js:76:40)
    at link (internal/modules/esm/module_job.js:75:36)

I've tried to check your example svelte-kit to see if there was anything different in the config, but couldn't find anything. I've almost taken verbatim the code you had in your example. this is the relevant part from my index.svelte

	import { ApolloClient, InMemoryCache, gql } from "@apollo/client/core";
	import { setClient, query, mutation } from "svelte-apollo";	
  import { AGENTS } from '$lib/queries'
	const client = new ApolloClient({
		uri: "https://yq4l7sc1.directus.app/gql",
		cache: new InMemoryCache()
	});
	setClient(client);

happysalada avatar Feb 28 '22 03:02 happysalada

I have experienced the same thing. @timhall any insight on this?

Luppilau avatar Mar 27 '22 00:03 Luppilau

I took the zip of this great project, extracted the sveltekit example and run into the same issue.

Following proposed fixed, I tried:

import pkg from '@apollo/client/core/core.cjs';
const { InMemoryCache, gql } = pkg;
import { ApolloClient } from '@apollo/client/core/ApolloClient';

without luck, now with error in the apollo module itself .../node_modules/@apollo/client/utilities/globals/fix-graphql.js:1 import { remove } from "ts-invariant/process/index.js";

j2l avatar Apr 05 '22 13:04 j2l

Adding this to my svelte.config.js worked:

      optimizeDeps: {
        exclude: ['@apollo/client', 'svelte-apollo'],
      },
      ssr: {
        noExternal: ['@apollo/client', 'svelte-apollo'],
      },

to kit.vite

lorensr avatar May 22 '22 19:05 lorensr