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

SvelteKit, Vite and Prisma "module not defined" #10404

Closed
wvhulle opened this issue Nov 23, 2021 · 3 comments
Closed

SvelteKit, Vite and Prisma "module not defined" #10404

wvhulle opened this issue Nov 23, 2021 · 3 comments
Labels
bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. kind/bug A reported bug. team/client Issue for team Client. topic: prisma-client topic: sveltekit
Milestone

Comments

@wvhulle
Copy link

wvhulle commented Nov 23, 2021

Bug description

When running SvelteKit with Prisma, I get the following on importing Prisma:

module is not defined

node_modules/.prisma/client/index-browser.js@http://localhost:3000/node_modules/.vite/@prisma_client.js?v=e1c45a9b:19:5
__init@http://localhost:3000/node_modules/.vite/chunk-PU3FFY2K.js?v=e1c45a9b:4:50
node_modules/@prisma/client/index-browser.js@http://localhost:3000/node_modules/.vite/@prisma_client.js?v=e1c45a9b:28:19
__require@http://localhost:3000/node_modules/.vite/chunk-PU3FFY2K.js?v=e1c45a9b:7:44
@http://localhost:3000/node_modules/.vite/@prisma_client.js?v=e1c45a9b:34:29

How to reproduce

  1. NPM install
  2. Import Prisma with
import { PrismaClient, Process } from '@prisma/client'
const prisma = new PrismaClient()
  1. npm run dev

Expected behavior

Normal loading of the page

Prisma information

Queries of schema in API route endpoints. Such as for example

const prisma = new PrismaClient()


export async function get() {
    const targets = await prisma.thing.findMany({

        where: {
            roles: {
                some: {
                    target: true
                }
            }
        }
    })

    return { body: targets }
}

Environment & setup

  • OS: Manjaro
  • Database: PostgreSQL
  • js version: v16.11.1

Prisma Version

prisma                  : 3.5.0
@prisma/client          : 3.5.0
Current platform        : debian-openssl-1.1.x
Query Engine (Node-API) : libquery-engine 78a5df6def6943431f4c022e1428dbc3e833cf8e (at node_modules/@prisma/engines/libquery_engine-debian-openssl-1.1.x.so.node)
Migration Engine        : migration-engine-cli 78a5df6def6943431f4c022e1428dbc3e833cf8e (at node_modules/@prisma/engines/migration-engine-debian-openssl-1.1.x)
Introspection Engine    : introspection-core 78a5df6def6943431f4c022e1428dbc3e833cf8e (at node_modules/@prisma/engines/introspection-engine-debian-openssl-1.1.x)
Format Binary           : prisma-fmt 78a5df6def6943431f4c022e1428dbc3e833cf8e (at node_modules/@prisma/engines/prisma-fmt-debian-openssl-1.1.x)
Default Engines Hash    : 78a5df6def6943431f4c022e1428dbc3e833cf8e
Studio                  : 0.439.0
@wvhulle wvhulle added the kind/bug A reported bug. label Nov 23, 2021
@Jolg42 Jolg42 added bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. topic: prisma-client topic: sveltekit team/client Issue for team Client. labels Dec 2, 2021
@Jolg42
Copy link
Member

Jolg42 commented Dec 2, 2021

Does this help maybe? (there are also more comments in this issue about SvelteKit)
#5030 (comment)

@wvhulle
Copy link
Author

wvhulle commented Dec 2, 2021

I ended up switching between the dev and production mode with the following script. I found this somewhere else in the issues but changed it a bit.

import pkg, { PrismaClient } from '@prisma/client';
import { dev } from '$app/env';

declare global {
	var _prisma: PrismaClient; // eslint-disable-line
}

let prisma;
if (dev) {
	if (!global._prisma) {
		global._prisma = new PrismaClient();
	}
	prisma = global._prisma;
} else {
	const { PrismaClient } = pkg;
	prisma = new PrismaClient();
}

export default prisma as PrismaClient; // type assertion for shim

This solved one big issue for me which was that the app wouldn't run in production mode. Maybe it was not exactly the same issue, but now I don't have to thing about how to import prisma anymore. I just import prisma from this script.

nikolai-cc added a commit to stackabletech/feature-tracker that referenced this issue Jan 6, 2022
nikolai-cc added a commit to stackabletech/feature-tracker that referenced this issue Jan 6, 2022
@millsp
Copy link
Member

millsp commented May 13, 2023

Hey @wvhulle I recently re-wrote our tests to the latest SvelteKit and Prisma version, and can confirm this is fixed.
https://github.com/prisma/ecosystem-tests/tree/dev/frameworks/sveltekit

I am therefore closing this issue, but let me know you need anything.

@millsp millsp closed this as completed May 13, 2023
@millsp millsp added this to the 4.15.0 milestone May 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. kind/bug A reported bug. team/client Issue for team Client. topic: prisma-client topic: sveltekit
Projects
None yet
Development

No branches or pull requests

3 participants