Closed alexgorbatchev closed 1 year ago
Before adding a configuration option, I’d like to understand how Nextjs is resolving your pages directory in your project. I would expect the Nextjs process to encounter the same issue. If it doesn’t, I’d like to mirror their approach.
JavaScript monorepos generally define a package.json per package or application in the monorepo, and the working directory is resolved relative to that package.json when executing commands across the repo (lerna, yarn workspaces, etc).
Could you share a minimal example project with your Nx setup? https://github.com/tatethurston/nextjs-routes/issues/73#issuecomment-1300676454 and share how you’re invoking next commands?
@tatethurston sure, try this https://stackblitz.com/edit/nextjs-bzas5l?file=README.md
I just installed nx and generated next app with it, and added nextjs-routes
, nothing else.
JavaScript monorepos generally define a package.json per package or application in the monorepo, and the working directory is resolved relative to that package.json when executing commands across the repo (lerna, yarn workspaces, etc).
Nx monorepo setup does support that, however default setup is a single package.json
file in the root. https://nx.dev/getting-started/integrated-repo-tutorial
I looked into this and the next
commands accept a directory as their first argument, otherwise falling back to the cwd. I think (but haven’t yet confirmed) this is how the nx next package is working.
I think we should be able to do the same from process.argv so clients don’t need to configure anything
I believe that the issue here is that the NX builder doesn't allow for that property to be passed to to next
@alexgorbatchev Is additional configuration necessary in your nx example? When I remove withRoutes
from nextjs-routes
, I see the following nextjs error:
Error: > Couldn't find a `pages` directory. Please create one under the project root
at Object.findPagesDir (/home/projects/nextjs-rv54c8/node_modules/next/dist/lib/find-pages-dir.js:42:19)
at new DevServer (/home/projects/nextjs-rv54c8/node_modules/next/dist/server/dev/next-dev-server.js:107:66)
at NextServer.createServer (/home/projects/nextjs-rv54c8/node_modules/next/dist/server/next.js:137:20)
at eval (/home/projects/nextjs-rv54c8/node_modules/next/dist/server/next.js:149:42)
https://stackblitz.com/edit/nextjs-rv54c8?file=myorg%2Fpackages%2Fweb%2Fnext.config.js
i cleaned up the demo, it was trying to npm start
from root, try cd myorg && npm start
Did some digging into the nx
nextjs wrapper because I wanted to understand how they are resolving the pages directory. nx creates a custom nx
server: https://github.com/nrwl/nx/blob/94edbe9f6ce808ec9296954ea4333d7698f34e1e/packages/next/src/executors/server/server.impl.ts#L94 and passes in the project directory.
Adds an option to pass
cwd
to avoid having to do this workaround https://github.com/tatethurston/nextjs-routes/issues/73#issuecomment-1299529571