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

Test failing in vitest #493

Open
hyochan opened this issue Mar 31, 2023 · 1 comment
Open

Test failing in vitest #493

hyochan opened this issue Mar 31, 2023 · 1 comment
Labels
esm type/bug Something is not working the way it should

Comments

@hyochan
Copy link

hyochan commented Mar 31, 2023

Screenshot 2023-03-31 at 7 59 00 PM

I added below after above screenshot appears.

deps: {
  inline: [
    "nexus-prisma"
  ]
}

Then the result becomes

 FAIL  tests/api.test.ts [ tests/api.test.ts ]
Error: Failed to load url .nexus-prisma (resolved id: .nexus-prisma) in /Users/node_modules/nexus-prisma/dist-esm/entrypoints/main.js. Does the file exist?
 ❯ loadAndTransform node_modules/vite/dist/node/chunks/dep-79892de8.js:41096:21

Any idea how to resolve this 🤔?

@hyochan hyochan added the type/bug Something is not working the way it should label Mar 31, 2023
@frontendphil
Copy link

We had a similar issue. As a workaround we've added a custom script that creates a "bridge" in betwen esm and cjs code.

import { mkdirSync, writeFileSync } from "fs"
import nexusPrisma from "nexus-prisma"
import { fileURLToPath } from "url"

const index = Object.keys(nexusPrisma)
  .map((key) => `export const ${key} = nexusPrisma.${key}`)
  .join("\n")

const root = new URL("nexus/", import.meta.url)

mkdirSync(fileURLToPath(root), { recursive: true })

writeFileSync(
  fileURLToPath(new URL(`./index.ts`, root)),
  [`import nexusPrisma from "nexus-prisma"`, index].join("\n"),
)

I've also added a path alias to @/nexus and only imported from there. It's not ideal, but it helps for the transitioning phase.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
esm type/bug Something is not working the way it should
Projects
None yet
Development

No branches or pull requests

3 participants