The Problem:
@nrwl/node
generator fails with error Cannot find module 'nx/src/utils/code-frames'
for NX version 15.2.1, @nrwl/node
version 15.9.2, and Node.js version 16.17.0, despite reinstalling the packages multiple times.
The Solutions:
Solution 1: Check and fix version consistency
The issue arises due to a version mismatch between nx
and @nrwl/node
. To resolve this, ensure that both packages have the same version.
Run nx workspace-lint
or nx report
to identify any version inconsistencies.
To rectify the versions, use the command nx migrate latest
. This command will automatically update nx
and @nrwl/node
to the latest compatible versions, resolving the error.
Solution 2: Fix Version Misalignment
Run nx report
to check for version misalignment in your installed packages. You might see a report like:
> NX Some packages have misaligned versions! These packages should
> match your installed version of Nx.
> – @nrwl/[email protected]
> – @nrwl/[email protected]
> – @nrwl/[email protected]
> – @nrwl/[email protected]
> – @nrwl/[email protected]
To fix this, run nx migrate 15.9.3
to align the package versions to the latest stable Nx release.
After running the migration command, execute yarn
or npm i
to update the packages. This should resolve the version conflict and allow you to generate a new node project without the nx/src/utils/code-frames
error.
Solution 3: Check versioning scheme
Ensure that all your @nrwl
packages have consistent versioning schemes. Verify that the versions match not only in numbers but also in the versioning scheme, such as using the caret symbol (^
) or not. If there’s a mismatch, remove any discrepancies in the versioning scheme to resolve the issue.
Q&A
What happens if nx
and nrwl/node
are not the same version?
You should see an error if you run nx workspace-lint
or nx report
and nx migrate will fix this.
What if nx migrate 15.9.3
does not solve the issue?
Check to see if your dependency versions match in both number and versioning scheme.
Video Explanation:
The following video, titled "ESLint: Your Nx Workspace Rules - James Henry - Nx Conf 2021 ...", provides additional insights and in-depth exploration related to the topics discussed in this post.
... Nrwl and Nx on Twitter: https://twitter.com/nrwl_io https://twitter.com/nxdevtools Join the Nx Community Slack at https://go.nrwl.io/join-slack.
The following video, titled "ESLint: Your Nx Workspace Rules - James Henry - Nx Conf 2021 ...", provides additional insights and in-depth exploration related to the topics discussed in this post.
... Nrwl and Nx on Twitter: https://twitter.com/nrwl_io https://twitter.com/nxdevtools Join the Nx Community Slack at https://go.nrwl.io/join-slack.