blomqma / next-rest-framework

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

Unable to generate docs #131

Closed Type1J closed 5 months ago

Type1J commented 6 months ago

I have an issue similar to #129 . I have used create-next-app to create the project, installed zod 3.22.2, and next-rest-framework.

Running next-rest-framework generate (from either an npm run script or npx) says Compiling endpoints... followed by many TypeScript errors. My tsconfig.json is the default generated by create-next-app, and I can run npm run dev with no issues. However, I can't get the openapi.json file generated.

Please help!

Type1J commented 6 months ago

Note that the TypeScript errors are all from node_modules, not the project code.

blomqma commented 6 months ago

Which version of next-rest-framework are you using? I'm unable to reproduce this with the instructions you provided, do you have a reproducible example?

birbprophet commented 5 months ago

@blomqma I am facing the exact same issue. I can add you to my repo if you want yo know more about this issue.

itsjxck commented 5 months ago

This change breaks openapi.json generation for us. I just upgraded from v5.1.3 to v5.1.9 and suddenly I get an openapi.json file that has an empty paths object. Diving into the node_modules and commenting out the line packages: "external" fixes this for me.

blomqma commented 5 months ago

This change breaks openapi.json generation for us. I just upgraded from v5.1.3 to v5.1.9 and suddenly I get an openapi.json file that has an empty paths object. Diving into the node_modules and commenting out the line packages: "external" fixes this for me.

Thanks, seems like the external packages option needs to be dropped for now, I have included that fix in v5.1.10. Would be great to confirm if this fix addresses the issue for others as well as I'm still unable to reproduce this myself.

Type1J commented 5 months ago

It seems unrelated. The original problem seems to have something to do with esbuild not ignoring node_modules for TypeScript.

birbprophet commented 5 months ago

Tested v5.1.10 and the same errors are still happening.

mirko314 commented 5 months ago

Running into the same issue, even on 5.1.10. Replacing the following function in node_modules/next-rest-framework/dist/cli/index.js

var compileEndpoints = async () => {
  await clearTmpFolder();
  console.info(import_chalk2.default.yellowBright("Compiling endpoints..."));
  const entryPoints = await (0, import_tiny_glob.default)("./**/*.ts");
  await (0, import_esbuild.build)({
    entryPoints,
    bundle: true,
    format: "cjs",
    platform: "node",
    outdir: NEXT_REST_FRAMEWORK_TEMP_FOLDER_NAME,
    outExtension: { ".js": ".cjs" }
  });
};

with this one , basically changing the entrypoints from ./ to ./src, solves it for me. Maybe this helps debugging this issue, it's certainly not a long term solution unfortunatly

var compileEndpoints = async () => {
  await clearTmpFolder();
  console.info(import_chalk2.default.yellowBright("Compiling endpoints..."));
  const entryPoints = await (0, import_tiny_glob.default)("./src/**/*.ts");
  await (0, import_esbuild.build)({
    entryPoints,
    bundle: true,
    loader: {
      ".node": "file" // needed for "sharp"
    },
    format: "cjs",
    platform: "node",
    outdir: NEXT_REST_FRAMEWORK_TEMP_FOLDER_NAME,
    outExtension: { ".js": ".cjs" }
  });
};
itsjxck commented 5 months ago

This change breaks openapi.json generation for us. I just upgraded from v5.1.3 to v5.1.9 and suddenly I get an openapi.json file that has an empty paths object. Diving into the node_modules and commenting out the line packages: "external" fixes this for me.

Thanks, seems like the external packages option needs to be dropped for now, I have included that fix in v5.1.10. Would be great to confirm if this fix addresses the issue for others as well as I'm still unable to reproduce this myself.

Upgrading to v5.1.10 fixes this for us. I also cannot reproduce the behaviour others are having.

basically changing the entrypoints from ./ to ./src, solves it for me

@mirko314 unfortunately this will break for anyone not using the src directory. If others who are using the src directory can test this solution though, or at least confirm whether or not they are using the src directory while seeing these issues, it might be a case of just adding something like

  const entryPoints = await (0, import_tiny_glob.default)(srcExists ? "./src/**/*.ts" : "./**/*.ts");
blomqma commented 5 months ago

Did some more digging and was finally able to reproduce and fix this in https://github.com/blomqma/next-rest-framework/pull/141. This problem only occurs when using npm which treats the node_modules folder differently than e.g. pnpm. The node_modules folder is now explicitly ignored by a different globbing algorithm that fixes the issue for npm/npx. Upgrading to v5.1.11 should address this so closing this issue for now, thanks for the help!