graphql-nexus / nexus

Code-First, Type-Safe, GraphQL Schema Construction
https://nexusjs.org
MIT License
3.4k stars 275 forks source link

Guide for generating nexus in ESM #1155

Open hyochan opened 1 year ago

hyochan commented 1 year ago

Hi! Thanks for awesome library nexus. I've been using this for many years now. Today, I am looking to upgrade our project to ESM and I am stuck in error when generating nexus.

It shows the below error.

TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" for /Users/hyo/Github/app/server/src/schema.ts
    at new NodeError (node:internal/errors:399:5)
    at Object.getFileProtocolModuleFormat [as file:] (node:internal/modules/esm/get_format:79:11)
    at defaultGetFormat (node:internal/modules/esm/get_format:121:38)
    at defaultLoad (node:internal/modules/esm/load:81:20)
    at nextLoad (node:internal/modules/esm/loader:163:28)
    at ESMLoader.load (node:internal/modules/esm/loader:605:26)
    at ESMLoader.moduleProvider (node:internal/modules/esm/loader:457:22)
    at new ModuleJob (node:internal/modules/esm/module_job:64:26)
    at ESMLoader.#createModuleJob (node:internal/modules/esm/loader:480:17)
    at ESMLoader.getModuleJob (node:internal/modules/esm/loader:434:34) {
  code: 'ERR_UNKNOWN_FILE_EXTENSION'
}

And this is because I change the type to module in package.json. This error can be found in https://stackoverflow.com/questions/63386054/typeerror-err-unknown-file-extension-unknown-file-extension-ts-on-visual-s.

I tried to look over the document in the repo but I can't find anywhere to generate nexus safely when type: module is on. I hope I can get help on setting up nexus with ESM!

Thanks in advance.

binary64 commented 5 months ago

Use esbuild to compile it first