oscartbeaumont / vite-plugin-relay

A vite plugin for Relay
MIT License
79 stars 14 forks source link

Issues with root + tsconfigPaths paths setup #475

Open Meemaw opened 1 year ago

Meemaw commented 1 year ago

Hi. I'm trying to use vite-plugin-relay on a project that uses src as the root, and uses tsconfig paths for absolute imports.

vitest.config.ts

import react from "@vitejs/plugin-react"
import tsconfigPaths from "vite-tsconfig-paths"
import { defineConfig } from "vitest/config"
import relay from "vite-plugin-relay"

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [react(), tsconfigPaths(), relay],
  test: {
    globals: true,
    environment: "jsdom",
    setupFiles: ["./__tests__/setupVitestTests.ts"]
  },
  root: "src",
})

relay.config.js

module.exports = {
  src: "./src",
  schema: "./schema.graphql",
  schemaExtensions: ["./src"],
  exclude: [
    "**/__generated__/**",
    "**/__mocks__/**",
    "**/node_modules/**",
    "src/.next/**",
  ],
  language: "typescript",
  eagerEsModules: true,
  artifactDirectory: "./src/lib/graphql/__generated__",
}

tsconfig paths:

"paths": {
   "@/*": ["./*"]
}

Imports:

import { CollectionWatchlistButtonTestQuery } from "@/lib/graphql/__generated__/CollectionWatchlistButtonTestQuery.graphql"

When trying to run tests, vitest fails to find generated modules:

Screenshot 2023-05-31 at 08 16 40
criskell commented 6 months ago

Any solution? Same here