ckastbjerg / next-type-safe-routes

Never should your users experience broken links again!
MIT License
70 stars 5 forks source link

Next build fails when there is no `/pages/api` directory in project #30

Closed onvlt closed 2 years ago

onvlt commented 2 years ago

Build fails with following message

Error: ENOENT: no such file or directory, lstat '<project-path>/pages/api'
    at Object.realpathSync (node:fs:2486:7)
    at _walkSync (<project-path>/node_modules/walk-sync/index.js:109:25)
    at Object.walkSync [as default] (<project-path>/node_modules/walk-sync/index.js:20:12)
    at Object.generateTypeScriptFile (<project-path>/node_modules/next-type-safe-routes/dist/plugin/generateTypeScriptFile/generateTypeScriptFile.js:19:44)
    at writeTypesToDisc (<project-path>/node_modules/next-type-safe-routes/dist/plugin/index.js:20:58)
    at Object.webpack (<project-path>/node_modules/next-type-safe-routes/dist/plugin/index.js:36:13)
    at Object.getBaseWebpackConfig [as default] (<project-path>/node_modules/next/dist/build/webpack-config.js:1364:32)
    at async Promise.all (index 0)
    at async Span.traceAsyncFn (<project-path>/node_modules/next/dist/trace/trace.js:74:20)
    at async Span.traceAsyncFn (<project-path>/node_modules/next/dist/trace/trace.js:74:20) {
  errno: -2,
  syscall: 'lstat',
  code: 'ENOENT',
  path: '<project-path>/pages/api'
}

Expected behavior

Since API routes are optional in Next, I don't think it should fail upon their absence.

kopach commented 1 year ago

is this released to NPM?