-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
next: The @nrwl/next:build executor is incompatible with Next 13.2 #15214
Comments
Also happened to us for updating to 13.2.1
stacktrace:
|
NextJS Issue tracking this problem (impacting other folk too): vercel/next.js#46374 |
Reading the "tracking" of this issue. It seems like, "hey, you are using undocumented and unsupported features from the dist folder. " This likely means that the fix needs to come from Nrwl, not NextJS. |
any update from Nrwl? |
Still waiting This issue is critical eh. Is there any workarounds for now? |
+1, we are building next.js app with |
creading adoption issues at our end as well |
Temporary workaround, tested in
in your next.config.js: const withNx = require("@nrwl/next/plugins/with-nx");
/**
* @type {import('@nrwl/next/plugins/with-nx').WithNxOptions}
**/
const nextConfig = {
reactStrictMode: true,
+ distDir: "../../dist/apps/my-app/.next", // this is usually set by @nrwl/next:build, but silently fails in [email protected]+
+ transpilePackages: ["@my-npm-scope/my-package"], // for whatever module fails the build :/
+ // if you use nextjs appdir; there is a bug in next where their typescript plugin generates a wrong import path for pages
+ // maybe you can also fix with patch-package
+ typescript: {
+ ignoreBuildErrors: true,
+ },
nx: {
svgr: false,
},
// ...
};
module.exports = withNx(nextConfig); Worth noting that in our case we also have: output: "standalone",
experimental: {
appDir: true,
outputFileTracingRoot: path.join(__dirname, "../../"),
}, |
@ianldgs, I'm a bit confused by your last message. Could you please clarify whether the workaround you provided in the configuration would make it work? Thank you. |
@ruslanguns the workaround made it work for our project. But we don't use any of the features NX provides for NextJS. |
Thanks @ianldgs , I tested but got some weird behaviours, I rather downgraded NextJS to v13.1.1 which works smoothly with Next 15.8.1 |
It's definitely not a production-ready solution :p From what I peaked at the source code of |
For a more concrete explanation of what's happening:
So basically for now the only solution is to downgrade nextjs' version. I wonder if you can configure all things via the nextjs' cli command. If so, something that executes the build command passing the command via CLI would be a way 🤔 |
Ah, hey @rmachado-studocu! Nice to bump into you over the internets 🙃 So, the reason NX has to pass the config to the build function is for the features I mentioned in this comment: If you don't use those features, all you have to do is specify the |
I switched to Nx to 15.8.1 and Nx to 13.1.1 build throws this error Can you please provide how you can run it? UPD: Updated all modules to 15.8.1 But still not working |
@skaneprime I think that's because the NX Cli doesn't support the appDir functionality yet. So, maybe you should consider follow the steps provided by @ianldgs above ☝️. |
@ianldgs solution works as a workaround for me. I had to remove the distDir line from the next.config.js in the dist folder though. Removing that line can also be done programmatically, if you want to use it in a build script: sed -i '' "/distDir/d" "./dist/apps/web/next.config.js" Also I changed my distDir config to: distDir: "../../dist/apps/web/.next", |
This did work for me too! Thanks! |
I was testing out Turborepo, and Next run fine. That's going to be pretty obvious. Really, this is just because that monorepo tool is layered on top of the package manager's workspace features. Well, Nx supports that as well. So, while it is a bit different, it does seem that you could just set up your app and UI components libs as NPM/PNPM/Yarn workspaces. Parts of the solution, like Tailwind, can end up more manual maybe. /** @type {import("tailwindcss").Config} */
const config = {
content: [
'./src/**/*.{js,ts,jsx,tsx}',
'../../packages/ui/**/*.{js,ts,jsx,tsx}',
],
theme: {
extend: {},
},
plugins: [],
};
module.exports = config; Where there are relative paths for processing. But, this is largely what the Nx tailwind Plugin does anyway and might still work fine. |
Is your '../../dist/apps/web/.next' directory outside the Next.js app project directory? Would having a 'distDir' outside the project directory work well considering this warning from the Next.js documentation: My workaround that seems to work so far for all the @nrwl:next executors is (1) leave/keep the '.next' 'distDir' default within the next.js app project directory/root, then (2) symlink (on Linux) that default '.next' directory to the '.next' directory within the dist directory I have set for 'outputPath' in project.json (i.e. the default 'outputPath' setting when the app is generated with NX). NX 15.8.5 and Next.js 13.2.3 seem to co-exst somewhat 'peacefully' that way. I still have this warning coming up, though: "Skipping project found at packages/apps/APP/.next since project .next already exists at packages/apps/ANOTHER-APP-built-earlier/.next! Specify a unique name for the project to allow Nx to differentiate between the two projects." although project names are completely different. The warning went away briefly after a reset the NX workspace. |
I got the same warning on pnpm-workspaces, I changed pnpm-lock.yaml from
to:
it was searching the sub-directories for package.json files by default |
Wouldn't that kill libs feature? |
This issue is a showstopper, to put it kindly. Is Nrwl aware that importing a component from a lib breaks when using Next.js 13.2+? |
@jaysoo I see you're working with adding appDir support to the generator in #15569. |
They are not commenting here, but it seems Nrwl is aware of the issue: |
Update: it seems like [email protected] has fixed this. For some strange reason, even after upgrading to [email protected] and [email protected], my
The failure is coming from importing components from another package (in this example, However, as long as I add the following empty array to
...then my build is working again. I have no idea why this works, but just putting it out here for those trying shopping around for a fix 🍀 |
I am still seeing some loader issues on the latest that are not related to importing across projects. I seem to get a related issue when I upgrade # next upgrade to 13.2.4 from 13.1.6
../../libs/api/src/lib/constants.ts
Module parse failed: Unexpected token (5:2)
File was processed with these loaders:
* ../../node_modules/next-translate/lib/cjs/plugin/loader.js
You may need an additional loader to handle the result of these loaders.
| export const API_ENDPOINT = (
| HAVE_WINDOW ? process.env['NEXT_PUBLIC_API'] : process.env['NEXT_PUBLIC_API_SSR']
> ) as string
Import trace for requested module:
../../libs/api/src/lib/constants.ts
../../libs/api/src/index.ts # nx upgrade to 15.8.7 from 15.8.6 (continues with next upgrade)
../../libs/api/src/lib/constants.ts
Module parse failed: Unexpected token (5:2)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
| export const API_ENDPOINT = (
| HAVE_WINDOW ? process.env['NEXT_PUBLIC_API'] : process.env['NEXT_PUBLIC_API_SSR']
> ) as string
Import trace for requested module:
../../libs/api/src/lib/constants.ts
../../libs/api/src/index.ts |
I have the the issue
with following setup
|
Using: You can also try this workaround: // ... your next config file
module.exports = (phase) => ({
...nextConfig,
distDir: phase === PHASE_PRODUCTION_BUILD ? '../../dist/apps/<YOUR_APP_PATH>/.next' : '.next',
}); This way you only change the output at build time and at runtime all stays the same. |
@gilmillasseau Are you dropping out |
I solved it by refactoring it to: // Example NxNext Configuration
const nextConfig = {
nx: {
svgr: false,
},
eslint: {
ignoreDuringBuilds: false,
},
};
module.exports = async (phase) => {
const nxConfig = await withNx(nextConfig)(phase);
const config = withSentry(withPlausible(nxConfig));
return config;
}; |
This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context. |
Current Behavior
When using
@nrwl/next@latest
with[email protected]
, the@nrwl/next:build
executor doesn't respect the executor options.The
.next
folder is built inline (e.g.apps/X/.next
) rather than in the configuredouputPath
(e.g.dist/apps/X/.next
).This issue is due to an internal breaking change in version 13.2.0 of Next that removed the custom
conf
option of thenext/dist/build
function: vercel/next.js#45455Expected Behavior
The
.next
build output should be located in theoutputPath
folder, e.g.dist/apps/X/.next
.GitHub Repo
https://github.com/jasongerbes/nx-examples/tree/next-13.2.0
Steps to Reproduce
@nrwl/next
test-next-app
next
to13.2.0
nx build test-next-app
Nx Report
Failure Logs
No response
Additional Information
No response
The text was updated successfully, but these errors were encountered: