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

Astro SSR + non-default Prisma schema cannot be bundled #11190

Closed
1 task
marvin-j97 opened this issue Jun 5, 2024 · 1 comment
Closed
1 task

Astro SSR + non-default Prisma schema cannot be bundled #11190

marvin-j97 opened this issue Jun 5, 2024 · 1 comment
Labels
needs triage Issue needs to be triaged

Comments

@marvin-j97
Copy link
Contributor

marvin-j97 commented Jun 5, 2024

Astro Info

Astro                    v4.9.3
Node                     v22.0.0
System                   Linux (x64)
Package Manager          pnpm
Output                   server
Adapter                  @astrojs/node
Integrations             none

If this issue only occurs in one browser, which browser is a problem?

No response

Describe the Bug

Prisma allows multiple schemas to be bundled into separate Prisma clients.

When using the default way to create a Prisma client and importing it (@prisma/client) into Astro, it works fine.

When importing one of those custom-output Prisma clients (which are accessed using relative path, see Repro Repo), the bundling fails because Prisma is CommonJS, but Astro is ESM:

17:58:01 [ERROR] [vite] x Build failed in 318ms
src/pages/index.astro (2:9): "PrismaClient" is not exported by "prisma/prismaclient/index-browser.js", imported by "src/pages/index.astro".

I don't think it's a bug inside Astro, it's probably either (1) a rollup configuration issue, and I'm too stupid for configuring rollup, or (2) a Rollup bug. However, dev (which uses esbuild), also doesn't work, so I think it's a configuration issue for both esbuild and rollup. But it is an issue with Astro I have unfortunately stumbled across. Maybe some Rollup magician knows a solution. In the end the issue is Prisma still does not output ESM...

In general I find it awkward that in Astro SSR I need to manually set Vite settings like:

const packageJson = JSON.parse(readFileSync("package.json", "utf-8"));
const deps = Object.keys(packageJson.dependencies);
const bundlingDeps = isDev ? [] : deps;

{
  // ... Astro config...
  vite: {
    ssr: {
      noExternal: bundlingDeps,
    },
  }
}

to bundle dependencies, so my production build is node_modules independent. It feels very hidden and not well documented. IMO it should even be the default to create a standalone build artifact. But that is another discussion entirely.

What's the expected result?

It's possible to use multiple prisma schemas.

Link to Minimal Reproducible Example

https://github.com/marvin-j97/astro-prisma-bundle-issue

Participation

  • I am willing to submit a pull request for this issue.
@matthewp
Copy link
Contributor

matthewp commented Jun 5, 2024

Closing as this is a non-Astro issue. We do special-case popular packages but since this is submodules specifically I don't think there's anything we can special-case here. I would just suggest using noExternal config as you are doing now, that's what the config is for.

@matthewp matthewp closed this as not planned Won't fix, can't repro, duplicate, stale Jun 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs triage Issue needs to be triaged
Projects
None yet
Development

No branches or pull requests

2 participants