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

[typegraphql-prisma] SyntaxError: Unexpected token 'export' #689

Closed
nikolasburk opened this issue Aug 29, 2020 · 2 comments
Closed

[typegraphql-prisma] SyntaxError: Unexpected token 'export' #689

nikolasburk opened this issue Aug 29, 2020 · 2 comments
Labels
Prisma 🔺 Issues about typegraphql-prisma integration Question ❔ Not future request, proposal or bug issue Solved ✔️ The issue has been solved

Comments

@nikolasburk
Copy link

I want to start exploring the typegraphql-prisma integration based on the existing TypeGraphQL + Prisma example in the prisma-examples repo.

Reproduce

To reproduce the error, you can set up the example:

git clone git@github.com:prisma/prisma-examples.git --depth=1
cd prisma-examples/typescript/graphql-typegraphql
npm install
npm run dev

The example itself doesn't use the integration yet, so I wanted to add it with the following steps. Installed the required deps:

npm i -D typegraphql-prisma
npm i graphql-type-json
npm i graphql-fields @types/graphql-fields

Then I added the generator:

generator typegraphql {
  provider = "typegraphql-prisma"
}

And ran npx prisma generate.

I then see the new files in node_modules/@generated/type-graphql.

Now I want to use some of the generated default resolvers and adjust src/index.ts as follows:

import "reflect-metadata";
import * as tq from "type-graphql";
import { PostResolver } from "./PostResolver";
import { UserResolver } from "./UserResolver";
import { GraphQLServer } from "graphql-yoga";
import { createContext } from "./context";
import {
  CreateUserResolver,
  UpdateUserResolver,
  DeleteUserResolver,
  FindOneUserResolver,
  FindManyUserResolver,
} from "@generated/type-graphql";

const app = async () => {
  const schema = await tq.buildSchema({
    resolvers: [PostResolver, UserResolver, CreateUserResolver, UpdateUserResolver, DeleteUserResolver, FindOneUserResolver, FindManyUserResolver],
  });

  const context = createContext();

  new GraphQLServer({ schema, context }).start(() =>
    console.log(`🚀 Server ready at: http://localhost:4000\n⭐️`)
  );
};

app();

However, when I'm trying to run this I'm getting the following error:

Using ts-node version 9.0.0, typescript version 3.8.3
/Users/nikolasburk/Desktop/prisma-examples/typescript/graphql-typegraphql/node_modules/@generated/type-graphql/index.ts:1
export * from "./enums";
^^^^^^

SyntaxError: Unexpected token 'export'
    at wrapSafe (internal/modules/cjs/loader.js:1053:16)
    at Module._compile (internal/modules/cjs/loader.js:1101:27)
    at Module._compile (/Users/nikolasburk/Desktop/prisma-examples/typescript/graphql-typegraphql/node_modules/source-map-support/source-map-support.js:547:25)
    at Module.m._compile (/private/var/folders/sy/wzhm36711zs2jwz7kzc86z3h0000gn/T/ts-node-dev-hook-12368100111403568.js:57:25)
    at Module._extensions..js (internal/modules/cjs/loader.js:1157:10)
    at require.extensions.<computed> (/private/var/folders/sy/wzhm36711zs2jwz7kzc86z3h0000gn/T/ts-node-dev-hook-12368100111403568.js:59:14)
    at Object.nodeDevHook [as .ts] (/Users/nikolasburk/Desktop/prisma-examples/typescript/graphql-typegraphql/node_modules/ts-node-dev/lib/hook.js:61:7)
    at Module.load (internal/modules/cjs/loader.js:985:32)
    at Function.Module._load (internal/modules/cjs/loader.js:878:14)
    at Module.require (internal/modules/cjs/loader.js:1025:19)
[ERROR] 08:47:51 SyntaxError: Unexpected token 'export'

Any thoughts on what I'm missing here?

@MichalLytek
Copy link
Owner

typegraphql-prisma generates TypeScript source code files, not compiled JS + d.ts files.

So if you emit the files to node_modules, they might be omitted by default TS config, so they won't be compiled and Node will occur some syntax errors because of that.

I think I should make that output setting explicit for now, until I start emit JS code to node_modules.

So please update your generator config block:

generator typegraphql {
  provider = "typegraphql-prisma"
  output   = "../prisma/generated/type-graphql"
}

Or try to include that node_modules folder in compilation step 😉

@MichalLytek MichalLytek added Prisma 🔺 Issues about typegraphql-prisma integration Question ❔ Not future request, proposal or bug issue labels Aug 29, 2020
@MichalLytek MichalLytek changed the title Issue with typegraphql-prisma integration: SyntaxError: Unexpected token 'export' [typegraphql-prisma] SyntaxError: Unexpected token 'export' Aug 29, 2020
@nikolasburk
Copy link
Author

Awesome, thanks for the prompt response! Changing the output path indeed solved the issue 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Prisma 🔺 Issues about typegraphql-prisma integration Question ❔ Not future request, proposal or bug issue Solved ✔️ The issue has been solved
Projects
None yet
Development

No branches or pull requests

2 participants