From a8ae302ae49f76aa068c90b59e935dcbc4deb46b Mon Sep 17 00:00:00 2001 From: Sean Parmelee Date: Tue, 4 Jun 2024 10:36:30 -0500 Subject: [PATCH] fix(nextjs): support canary versions of next (#22672) ## Current Behavior When using a `canary` version of `next` in an nx monorepo where the next.js application depends on a lib that's also in the monorepo, running `nx build` results in `Module parse failed: Unexpected token` errors start occurring. The use of a `canary` version essentially reintroduces https://github.com/nrwl/nx/issues/16658 because of how `semver` [handles pre-release tags](https://github.com/npm/node-semver/tree/main?tab=readme-ov-file#prerelease-tags). As mentioned in the docs, we can suppress this behavior by passing the `includePrerelease` option, which is what this PR does. ## Expected Behavior `nx build` successfully builds my Next.js application ## Related Issue(s) https://github.com/nrwl/nx/issues/16658 https://github.com/nrwl/nx/issues/16516 https://github.com/nrwl/nx/issues/19635 --- packages/next/plugins/with-nx.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/next/plugins/with-nx.ts b/packages/next/plugins/with-nx.ts index 8f3eb34129..ec728e7438 100644 --- a/packages/next/plugins/with-nx.ts +++ b/packages/next/plugins/with-nx.ts @@ -421,7 +421,7 @@ export function getAliasForProject( export function forNextVersion(range: string, fn: () => void) { const semver = require('semver'); const nextJsVersion = require('next/package.json').version; - if (semver.satisfies(nextJsVersion, range)) { + if (semver.satisfies(nextJsVersion, range, { includePrerelease: true })) { fn(); } }