Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error while building using vite #278

Open
andrea-benato-deltatre opened this issue Apr 8, 2024 · 1 comment
Open

Error while building using vite #278

andrea-benato-deltatre opened this issue Apr 8, 2024 · 1 comment

Comments

@andrea-benato-deltatre
Copy link

andrea-benato-deltatre commented Apr 8, 2024

HI!
I'm creating a library to wrap some precofigured hooks/funcs for my application.
Building it using vite I have this error while trying to import registerApolloClient:

RollupError: src/client/ssr.ts (2:9): "registerApolloClient" is not exported by "node_modules/.pnpm/@apollo+experimental-nextjs-app-support@0.10.0_@apollo+client@3.9.10_next@14.1.4_react@18.2.0/node_modules/@apollo/experimental-nextjs-app-support/dist/empty.js", imported by "src/client/ssr.ts".

Do you have any idea how to solve it? (I get that the error is related to the fact that the library exposes exports using reasct-server )

@phryneas
Copy link
Member

phryneas commented Apr 9, 2024

I get that the error is related to the fact that the library exposes exports using react-server

Yup, that's the problem. These functions do, in fact, not exist in the node or browser environments, which vite seems to assume here.

My first idea would be to tell vite in some way that @apollo+experimental-nextjs-app-support is external and should not be packaged. That might already keep it from looking at it and complaining about it.

If that's not working, you might have to compile the file in question with a react-server condition. If you have code that relies on node or browser features, that means that you'll have to split it up and compile it twice.

I believe the way of doing that would be a vite config like this:

import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";

export default defineConfig({
  plugins: [react()],
  resolve: {
    conditions: ["react-server"],
  },
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants