vite-plugin-node
vite-plugin-node copied to clipboard
Does not work with @nestjs/graphql
Reproduction: https://github.com/stevefan1999-personal/vite-plugin-node/tree/repo-graphql-failure/examples/nest
Log:
> [email protected] dev
> vite
vite v2.9.14 dev server running at:
> Local: http://localhost:3000/
> Network: use `--host` to expose
ready in 238ms.
reflect-metadata doesn't appear to be written in CJS, but also doesn't appear to be a valid ES module (i.e. it doesn't have "type": "module" or an .mjs extension for the entry point). Please contact the package author to fix.
[Nest] 23764 - 11/07/2022, 1:10:41 am LOG [NestFactory] Starting Nest application...
[Nest] 23764 - 11/07/2022, 1:10:41 am LOG [InstanceLoader] TypeOrmModule dependencies initialized +115ms
[Nest] 23764 - 11/07/2022, 1:10:41 am LOG [InstanceLoader] AppModule dependencies initialized +1ms
[Nest] 23764 - 11/07/2022, 1:10:41 am LOG [InstanceLoader] GraphQLSchemaBuilderModule dependencies initialized +1ms
[Nest] 23764 - 11/07/2022, 1:10:41 am LOG [InstanceLoader] GraphQLModule dependencies initialized +1ms
[Nest] 23764 - 11/07/2022, 1:10:41 am LOG [InstanceLoader] TypeOrmCoreModule dependencies initialized +22ms
[Nest] 23764 - 11/07/2022, 1:10:41 am LOG [InstanceLoader] TypeOrmModule dependencies initialized +1ms
[Nest] 23764 - 11/07/2022, 1:10:41 am LOG [InstanceLoader] UsersModule dependencies initialized +1ms
[Nest] 23764 - 11/07/2022, 1:10:41 am LOG [RoutesResolver] AppController {/}: +5ms
[Nest] 23764 - 11/07/2022, 1:10:41 am LOG [RouterExplorer] Mapped {/, GET} route +3ms
[Nest] 23764 - 11/07/2022, 1:10:41 am LOG [RouterExplorer] Mapped {/random, GET} route +1ms
[Nest] 23764 - 11/07/2022, 1:10:41 am LOG [RoutesResolver] UsersController {/}: +0ms
[Nest] 23764 - 11/07/2022, 1:10:41 am LOG [RouterExplorer] Mapped {/all, GET} route +1ms
[Nest] 23764 - 11/07/2022, 1:10:41 am LOG [RouterExplorer] Mapped {/add-random, GET} route +1ms
[Nest] 23764 - 11/07/2022, 1:10:41 am LOG [RouterExplorer] Mapped {/id/:id, GET} route +1ms
[Nest] 23764 - 11/07/2022, 1:10:42 am LOG [GraphQLModule] Mapped {/graphql, POST} route +120ms
[Nest] 23764 - 11/07/2022, 1:10:42 am LOG [NestApplication] Nest application successfully started +4ms
[Nest] 23764 - 11/07/2022, 1:10:43 am LOG [RoutesResolver] AppController {/}: +1595ms
[Nest] 23764 - 11/07/2022, 1:10:43 am LOG [RouterExplorer] Mapped {/, GET} route +1ms
[Nest] 23764 - 11/07/2022, 1:10:43 am LOG [RouterExplorer] Mapped {/random, GET} route +0ms
[Nest] 23764 - 11/07/2022, 1:10:43 am LOG [RoutesResolver] UsersController {/}: +1ms
[Nest] 23764 - 11/07/2022, 1:10:43 am LOG [RouterExplorer] Mapped {/all, GET} route +0ms
[Nest] 23764 - 11/07/2022, 1:10:43 am LOG [RouterExplorer] Mapped {/add-random, GET} route +1ms
[Nest] 23764 - 11/07/2022, 1:10:43 am LOG [RouterExplorer] Mapped {/id/:id, GET} route +0ms
C:\Users\steve\node\vite-plugin-node\examples\nest\node_modules\graphql\type\schema.js:219
throw new Error(
^
Error: Schema must contain uniquely named types but contains multiple types named "User".
at new GraphQLSchema (C:\Users\steve\node\vite-plugin-node\examples\nest\node_modules\graphql\type\schema.js:219:15)
at GraphQLSchemaFactory.create (C:\Users\steve\node\vite-plugin-node\examples\nest\node_modules\@nestjs\graphql\dist\schema-builder\graphql-schema.factory.js:40:24)
at GraphQLSchemaBuilder.generateSchema (C:\Users\steve\node\vite-plugin-node\examples\nest\node_modules\@nestjs\graphql\dist\graphql-schema.builder.js:36:52)
at GraphQLSchemaBuilder.build (C:\Users\steve\node\vite-plugin-node\examples\nest\node_modules\@nestjs\graphql\dist\graphql-schema.builder.js:23:31)
at GraphQLFactory.mergeWithSchema (C:\Users\steve\node\vite-plugin-node\examples\nest\node_modules\@nestjs\graphql\dist\graphql.factory.js:29:69)
at ApolloDriver.start (C:\Users\steve\node\vite-plugin-node\examples\nest\node_modules\@nestjs\apollo\dist\drivers\apollo.driver.js:19:51)
at GraphQLModule.onModuleInit (C:\Users\steve\node\vite-plugin-node\examples\nest\node_modules\@nestjs\graphql\dist\graphql.module.js:104:36)
at async callModuleInitHook (C:\Users\steve\node\vite-plugin-node\examples\nest\node_modules\@nestjs\core\hooks\on-module-init.hook.js:51:9)
at async NestApplication.callInitHook (C:\Users\steve\node\vite-plugin-node\examples\nest\node_modules\@nestjs\core\nest-application-context.js:178:13)
at async NestApplication.init (C:\Users\steve\node\vite-plugin-node\examples\nest\node_modules\@nestjs\core\nest-application.js:96:9)
It seems like we have duplicated instances of User class that has different resolution each time
Probably related: #50
anyone had any luck on getting this working in any form/with any versions out there? I've been swapping them out like crazy and nothing seems to work.
I got this to work importing from a package with "type": "module" and using yarn v3 / berry:
Create this patch file:
diff --git a/package.json b/package.json
index 11d979c..e07509d 100644
--- a/package.json
+++ b/package.json
@@ -4,6 +4,7 @@
"description": "Polyfill for Metadata Reflection API",
"main": "Reflect.js",
"types": "index.d.ts",
+ "type": "module",
"typescript": {
"definition": "Reflect.d.ts"
},
Then in your package json, add this resolutions block:
"resolutions": {
"reflect-metadata": "patch:[email protected]#./path/to/your/patchfile.patch"
},
If you are using a monorepo, this has to be at the top level package.json regardless of where you are importing reflect-metadata.
closing since there is a workaround.