Unverified Commit eab68a9f authored by Ian Luca's avatar Ian Luca Committed by GitHub

Ensure folder exists for standalone server (#44745)

When using standalone output in a monorepo, nextjs will sometimes throw:

`> NX ENOENT: no such file or directory, open
'/dist/apps/my-app/.next/standalone/apps/my-app/server.js'`

next.config.js:
```js
const { withNx } = require("@nrwl/next/plugins/with-nx");
const path = require("path");

/**
 * @type {import('@nrwl/next/plugins/with-nx').WithNxOptions}
 **/
const nextConfig = {
  output: "standalone",
  experimental: {
    outputFileTracingRoot: path.join(__dirname, "../../"),
  },
};

module.exports = withNx(nextConfig);
```

## Bug

- [x] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have a helpful link attached, see
[`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

Fixes https://github.com/nrwl/nx/issues/14112,
https://github.com/nrwl/nx/issues/9017

This `mkdir` instruction is the same as done for other parts of the
`copyTracedFiles` function. E.g. middlewares or pages.

Tested via publishing to an internal npm registry and pnpm overrides:
```json
  "pnpm": {
    "overrides": {
      "next": "npm:@internal/next@13.1.3-dev"
    }
  }
```
parent b6f6179d
...@@ -1725,6 +1725,7 @@ export async function copyTracedFiles( ...@@ -1725,6 +1725,7 @@ export async function copyTracedFiles(
path.relative(tracingRoot, dir), path.relative(tracingRoot, dir),
'server.js' 'server.js'
) )
await fs.mkdir(path.dirname(serverOutputPath), { recursive: true })
await fs.writeFile( await fs.writeFile(
serverOutputPath, serverOutputPath,
`${ `${
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment