에러코드
Oct 14th 09:42:30am ERRO micro: The file "/Users/........./dist/server.dev.js" does not export a function.
Oct 14th 09:42:30am ERRO micro: https://err.sh/micro/no-export
원인
이전코드
import "reflect-metadata";
import { ApolloServer } from "apollo-server-micro";
import micro, { send } from "micro";
import { get, post, router } from "microrouter";
import { buildSchemaSync } from "type-graphql";
import { UserResolver } from "./resolver/UserResolver";
import { registerEnum } from "./types/enum";
import { lexicographicSortSchema } from "graphql";
const graphqlPath = "/graphql";
const isDevelopmentBuild = process.env.NODE_ENV === "development";
const port = process.env.PORT || 3000;
registerEnum();
const schema = buildSchemaSync({
dateScalarMode: "timestamp",
resolvers: [UserResolver],
});
const apolloServer = new ApolloServer({
introspection: true,
playground: true,
schema: lexicographicSortSchema(schema),
});
const graphqlHandler = apolloServer.createHandler({ path: graphqlPath });
const mainHandler = router(
get(graphqlPath, graphqlHandler),
post(graphqlPath, graphqlHandler),
(_, res) => send(res, 404, "not found")
);
if (!isDevelopmentBuild) {
const server = micro(mainHandler);
server.listen(port);
}
수정코드
import "reflect-metadata";
import { ApolloServer } from "apollo-server-micro";
import micro, { send } from "micro";
import { get, post, router } from "microrouter";
import { buildSchemaSync } from "type-graphql";
import { UserResolver } from "./resolver/UserResolver";
import { registerEnum } from "./types/enum";
import { lexicographicSortSchema } from "graphql";
const graphqlPath = "/graphql";
const isDevelopmentBuild = process.env.NODE_ENV === "development";
const port = process.env.PORT || 3000;
registerEnum();
const schema = buildSchemaSync({
dateScalarMode: "timestamp",
resolvers: [UserResolver],
});
const apolloServer = new ApolloServer({
introspection: true,
playground: true,
schema: lexicographicSortSchema(schema),
});
const graphqlHandler = apolloServer.createHandler({ path: graphqlPath });
const mainHandler = router(
get(graphqlPath, graphqlHandler),
post(graphqlPath, graphqlHandler),
(_, res) => send(res, 404, "not found")
);
if (!isDevelopmentBuild) {
const server = micro(mainHandler);
server.listen(port);
}
export default mainHandler;