blomqma / next-rest-framework

Type-safe, self-documenting APIs for Next.js
https://next-rest-framework.vercel.app
Other
136 stars 18 forks source link

Generate command not working when package type is set to module #121

Closed joshdavenport closed 7 months ago

joshdavenport commented 7 months ago

I must be missing something, but I'm getting this error with 5.0.0:

Screenshot 2024-01-30 at 18 55 21

The file is definitely there, and it starts working when I remove "type": "module" from my package.json. Not sure if there is something bigger going on or I'm doing something silly!

mirko314 commented 7 months ago

Let me piggy back onto this issue. I do not the exact issue (since I'm using the default next js config which does not use type: module) but I also can not get the generate command to run and maybe these are related. I am running into an issue where next-rest-framework generate tries to typecheck all node_modules:


Compiling endpoints...
✘ [ERROR] The constant "Busboy" must be initialized

    node_modules/@fastify/busboy/lib/main.d.ts:11:13:
      11 │ export const Busboy: BusboyConstructor;
         ╵              ~~~~~~

✘ [ERROR] The constant "createAccordionScope" must be initialized

    node_modules/@radix-ui/react-accordion/dist/index.d.ts:6:13:
      6 │ export const createAccordionScope: import("@radix-ui/react-context"...
        ╵              ~~~~~~~~~~~~~~~~~~~~

✘ [ERROR] The constant "Accordion" must be initialized

My command: npx next-rest-framework generate --tsConfigPath /Users/[...]/tsconfig.json

blomqma commented 7 months ago

Let me piggy back onto this issue. I do not the exact issue (since I'm using the default next js config which does not use type: module) but I also can not get the generate command to run and maybe these are related. I am running into an issue where next-rest-framework generate tries to typecheck all node_modules:


Compiling endpoints...
✘ [ERROR] The constant "Busboy" must be initialized

    node_modules/@fastify/busboy/lib/main.d.ts:11:13:
      11 │ export const Busboy: BusboyConstructor;
         ╵              ~~~~~~

✘ [ERROR] The constant "createAccordionScope" must be initialized

    node_modules/@radix-ui/react-accordion/dist/index.d.ts:6:13:
      6 │ export const createAccordionScope: import("@radix-ui/react-context"...
        ╵              ~~~~~~~~~~~~~~~~~~~~

✘ [ERROR] The constant "Accordion" must be initialized

My command: npx next-rest-framework generate --tsConfigPath /Users/[...]/tsconfig.json

If your TS config has skipLibCheck set to true, then it should not check node_modules. I have also identified the original problem in this issue and working on a fix ASAP.

mirko314 commented 7 months ago

@blomqma That's weird because skipLibCheck: true is part of my TSConfig. This is my TSConfig (Standard from NextJS I think):

{
  "compilerOptions": {
    "target": "es5",
    "lib": ["dom", "dom.iterable", "esnext"],
    "allowJs": true,
    "skipLibCheck": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "noEmit": true,
    "esModuleInterop": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "jsx": "preserve",
    "incremental": true,
    "plugins": [
      {
        "name": "next"
      }
    ],
    "paths": {
      "@/*": ["./src/*"]
    }
  },
  "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
  "exclude": ["node_modules"]
}
blomqma commented 7 months ago

This is now fixed in v5.0.1. There was an issue with the extensions of the bundled code generated by the CLI causing those modules not working with the CLI Node.js process when explicitly using ESM. Now those file extensions are explicitly set to .cjs so they are always interpreted as CJS, making the CLI work with all module systems in your package.json.