'graphql syntax error inside schema with mogoose

schema

const { gql } = require("apollo-server-express");

export const typeDefs = gql`
type User {
    id: ID!
    name: String!
    email: String!
    password: String!
    otp: Float!
}
type Query {
    getUsers: [User]
    getUser(id: ID!): User
}
type Mutation {
    addUser(
    name: String!
    email: String!
    password: String!
    otp: Number!
    ): User
    updateUser(
    name: String!
    email: String!
    password: String!
    otp: Number
    ): User
    deleteUser(id: ID!): User
}
`;

error:

/Users/soubhagyapradhan/Desktop/upwork/school/schema.js:3
export const typeDefs = gql`
^^^^^^

SyntaxError: Unexpected token 'export'
    at Object.compileFunction (node:vm:352:18)
    at wrapSafe (node:internal/modules/cjs/loader:1031:15)
    at Module._compile (node:internal/modules/cjs/loader:1065:27)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (/Users/soubhagyapradhan/Desktop/upwork/school/server.js:3:16)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)
[nodemon] app crashed - waiting for file changes before starting...

here is my graphql schema. I have done the setup but i am getting this weird error saying syntax error Am i missing anything ?

please take a look what can be the issue Thanks

here i added my schema and error in console



Solution 1:[1]

Try module.exports = typeDefs at the end of the file instead of export.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 KONDRATJEV