Closed andirsun closed 1 year ago
Seeing same issue as well when trying to upgrade from nx 15.8.
I also tried playing with tsconfig to use swc and tsc as compilers and also tried targetting "node" but no dice.
same issue
because changed function withNx
...
Thanks for the repro, we'll investigate this.
We are also experiencing difficulties with the withNx function while attempting to upgrade our organization's repository.
A quick fix I found was to do the following:
// next.config.js
...
const getConfig = () => {
if (process.env.WITHOUT_NX) {
return nextConfig;
} else {
return withNx(nextConfig);
}
}
module.exports = getConfig();
and then simply set the env variables WITHOUT_NX
to true when running the cypress component testing to true
.
@Hamzakh777 Thanks! but I need to run the project using NX configuration.
@Hamzakh777 Without it, the library imports will not function properly, so this is not a viable workaround for me.
We are seeing a similar issue when upgrading nx from 15.8.6
to 16.3.2
(even without nextron): withNx
now returns a NextConfigFn
, so it's different than other plugins and different from before, where it returned a NextConfig
directly.
I tried to apply solutions described here:
but with no success.
What we have is:
const { withNx } = require('@nx/next/plugins/with-nx')
const nextConfig = { ... }
module.exports = async (phase, context) => {
const nxConfig = await withNx(nextConfig)(phase, context)
return nxConfig
}
nextConfig
. I tried with ours, with an empty one and with a default one ...withNx
:Error: Could not determine the config for this Next application.
at getNxContext (~/node_modules/.pnpm/@nx+next@16.3.2/node_modules/@nx/next/plugins/with-nx.js:70:15)
at ~/node_modules/.pnpm/@nx+next@16.3.2/node_modules/@nx/next/plugins/with-nx.js:95:106
at Generator.next (<anonymous>)
at fulfilled (~/node_modules/.pnpm/tslib@2.4.0/node_modules/tslib/tslib.js:115:62)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
Any help is really appreciated, thanks 🙏
Hey folks! @TkDodo just pinged me about this, so I took a look. I was able to make a fresh Next app with the @nx/next:application
generator that works in dev mode (looks like we call this target serve
in a fresh generated app).
Here's the next.config.js
file that was generated:
//@ts-check
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { composePlugins, withNx } = require('@nx/next');
/**
* @type {import('@nx/next/plugins/with-nx').WithNxOptions}
**/
const nextConfig = {
nx: {
// Set this to true if you would like to use SVGR
// See: https://github.com/gregberge/svgr
svgr: false,
},
};
const plugins = [
// Add more Next.js plugins to this list if needed.
withNx,
];
module.exports = composePlugins(...plugins)(nextConfig);
And here's the modifications I made to match the issue as reported:
//@ts-check
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { withNx } = require('@nx/next');
/**
* @type {import('@nx/next/plugins/with-nx').WithNxOptions}
**/
const nextConfig = {};
module.exports = withNx(nextConfig);
(^ repo: https://github.com/ZackDeRose/next-nx-bug - for dev mode: nx serve test
)
Both appear to work as expected. If I'm missing something though let me know and I can relay to our team!
@andirsun I cloned down your repo and saw the error as well.
In your case, this looks to be because you are ultimately running nextron
while our plugin seems to expect you to be using one of the expected @nx/next
executors, so when the task runs, it is not able to use the info from the nx graph and it errors out.
I was able to make it work via a hack: by removing your dev
npm script and instead adding the following configuration in your project.json
:
{
"name": "nextron",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "apps/nextron",
"projectType": "application",
"targets": {
// ...
"dev": {
"executor": "nx:run-commands",
"options": {
"command": "nextron",
"devServerTarget": "nextron:build",
"cwd": "apps/nextron"
}
}
},
"tags": []
}
^ having a devServerTarget
option present on the target is the "hack" that I'm using to end-around the fact that we're not using the expected @nx/next
targets here. I'll bring up options for a fix on this with the team, but hopefully this can get you through in the meantime.
My fork of your minimal repro repo: https://github.com/ZackDeRose/nx-nextron
To be clear, it was never our intention that withNx
works without our own, specific executors. However, after some thought, I think it makes sense to open up support so things continue to work for workspaces that rely on such behavior.
This PR relaxes the constraint, and should work for the cases outlined in this issue. https://github.com/nrwl/nx/pull/17819
To be clear, it was never our intention that withNx works without our own, specific executors.
hmm, it worked just fine with nx 15 tough :/
so, here's our situation:
@nx/next:build
to build our project - we are just running npx next build
in an nx:run-commands
executorwithNx
was breaking for us when starting our dev
task.the workaround that worked for us was:
"build-for-nx": {
"executor": "@nx/next:build",
"outputs": ["{options.outputPath}"],
"options": {},
"defaultConfiguration": "production"
},
note: it needs an empty options
object or it dies as well.
dev
task via the devServerTarget
option. Given an app named my-app
:"dev": {
"executor": "nx:run-commands",
"options": {
"commands": [
"NODE_OPTIONS=--max-old-space-size=8192 npx next dev,
],
"cwd": "packages/my-app",
"devServerTarget": "my-app:build-for-nx"
}
},
and then it started to work again.
@TkDodo I think it's a legit use case, just not something we designed for. I merged the PR to add support for all executors, so it will be fixed once we release a new version this week or next week.
The dummy target and dummy options won't be needed anymore either. I added e2e test to ensure support moving forward.
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
Hey! I am trying to use a nextron (https://github.com/saltyshiomix/nextron) project inside NX monorepo, nextron is a library that allow devs to run nextjs instance on electron.
I created this minimal repository to reproduce the error I am facing: https://github.com/andirsun/nx-nextron, it has a simple NX monorepo workspace with a single nextron project inside.
If you clone the repo and then try to run
npm run start:nextron
is working normally but at this point there is no connection with NX features likemodules/libs sharing
etc, thats why I want to modify the next.config.js using this function to use nx-next integrationBut if you try to export the next config using
withNx(nextConfig)
syntaxis, nextron stop working because of the renderer commandnext
How can I modify the
withNx(nextConfig)
function to work with nextron ?Expected Behavior
I suppose to run next and nextron normally with the same exported next configuration using
module.exports = withNx(nextConfig)
GitHub Repo
https://github.com/andirsun/nx-nextron
Steps to Reproduce
next.config.js
file and export next config as`module.exports = withNx(nextConfig)
Nx Report
Failure Logs
Additional Information
No response