nx: Collection "@nrwl/workspace" cannot be resolved.
Prerequisites
Expected Behavior
Have the following command working:
npx create-nx-workspace workspace --cli=angular --npm-scope=scope --preset=empty --skipGit=true --style=scss
Current Behavior / Failure Information (for bugs)
An unhandled exception occurred: Collection "@nrwl/workspace" cannot be resolved.
Steps to Reproduce
~/workspaces $ mkdir tmp
~/workspaces $ cd tmp/
~/workspaces/tmp $ npx create-nx-workspace workspace --cli=angular --npm-scope=scope --preset=empty --skipGit=true --style=scss
Context
~/workspaces/tmp $ yarn --version
1.22.4
~/workspaces/tmp $ node --version
v14.1.0
~/workspaces/tmp $ npm --version
6.14.4
~/workspaces/tmp $ uname -a
Linux nx--tools--dev--nx--latest-gkr8k 4.19.107 #1 SMP Thu Mar 26 11:33:10 PDT 2020 x86_64 Linux
~/workspaces/tmp $ cat /proc/version
Linux version 4.19.107 (jenkins@jenkins) (gcc version 7.4.0 (Buildroot 2019.02.10)) #1 SMP Thu Mar 26 11:33:10 PDT 2020
~/workspaces/tmp $ lsb_release -a
sh: lsb_release: not found
~/workspaces/tmp $ cat /etc/*release
3.11.6
NAME="Alpine Linux"
ID=alpine
VERSION_ID=3.11.6
PRETTY_NAME="Alpine Linux v3.11"
HOME_URL="https://alpinelinux.org/"
BUG_REPORT_URL="https://bugs.alpinelinux.org/"
Failure Logs
npx: installed 198 in 34.148s
Creating a sandbox with Nx...
warning @angular/cli > universal-analytics > request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
warning " > @nrwl/workspace@9.2.3" has incorrect peer dependency "prettier@^1.19.1".
new workspace "--npm-scope=scope" "--skipGit=true" --preset="empty" --interactive=false --collection=@nrwl/workspace
An unhandled exception occurred: Collection "@nrwl/workspace" cannot be resolved.
See "/tmp/ng-ahJOFF/angular-errors.log" for further details.
(node:847) UnhandledPromiseRejectionWarning: Error: Command failed: "/tmp/tmp-84746viJAJvJms6/node_modules/.bin/ng" new workspace "--npm-scope=scope" "--skipGit=true" --preset="empty" --interactive=false --collection=@nrwl/workspace
at checkExecSyncError (child_process.js:611:11)
at Object.execSync (child_process.js:647:15)
at createApp (/home/node/.npm/_npx/847/lib/node_modules/create-nx-workspace/bin/create-nx-workspace.js:343:21)
at /home/node/.npm/_npx/847/lib/node_modules/create-nx-workspace/bin/create-nx-workspace.js:76:21
(Use `node --trace-warnings ...` to show where the warning was created)
(node:847) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(node:847) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Other
- It was working for a while so it may be linked to new changes.
- There was an issue about it in the past: https://github.com/nrwl/nx/issues/1499
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 13
- Comments: 43 (6 by maintainers)
I have run into this error while trying to follow the Nx migration guide to bring a react app into Nx: https://nx.dev/react/migration/overview
I was able to run
npx create-nx-workspace@latestand create an empty workspace. The next suggested command failsnx generate @nrwl/react:application my-applicationwith “Collection “@nrwl/react” cannot be resolved.”Running
npm install @nrwl/reactseems to have resolved the problem. Perhaps consider adding this to the tutorial ifnx generate @nrwl/react:applicationis unable to install its own dependencies.Thanks a lot. it worked. i wonder why there is no mentions on this for empty workspaces.
Did you install the package ‘@nrwl/angular’?
Omg (!). I just noted that
nx@8said something different thannx@9I think the problem was because I asked for an empty workspace and it comes without
@nrwl/web- ok… Afternpm i @nrwl/webI couldnx generate @nrwl/web:app app1In that case - I’d suggest making the error-message clearer, and add a call-to-action to
npm ithe missing package. If you want to be ninjas - then notify the user that the package is missing and ask Y/N if she would like to install it and continue.The current message
Collection "@nrwl/web" cannot be resolvedfromnx@9sent me to the wrong places - as an nx beginner I don’t know what it means byCollection. I also could not find an arch overview of that thing or a glossary of concepts I can use to try to make sense of all that new things.I even tried install VSCode and use the VSCode plugin - but it got me the exact same, wrapped with the usual IDE golden-cage experience.
However -
nx@8saidCould not find module "@nrwl/web" from "/eval-nx".which was barely close enough to the familiarCould not find module "@nrwl/web".Should we close the issue?
I tried replicating in a docker and was unsuccessful. Can you post your
Dockerfileplease?This is mine:
Dockerfile:
Logs:
@FrozenPandaz @levani132 - I can confirm that my output is identical as well
npx create-nx-workspace workspacenx clicat /var/folders/g0/c7qwk52n1k5b20vy4sy9gdqm0000gn/T/tmp-25837YINyxEjsQZxz/package.jsonThank you for sharing your workaround @gund. On my side, I don’t want to have the ng CLI to be installed globally, same for installing
@nrwl/workspaceglobally, I would like to stay on locally installed package to prevent permissions issues (and other architecture issues that will come with it).One of the main issues with enhancing this specific error message, is that this is not code that’s specific to Nx, it comes from the schematics library that is used under the hood.
There might be a way to wrap it with a try/catch, but even then it’s not clear which plugin they want to install (could be
@nrwl/angular,@nrwl/nest,@nrwl/node,@nrwl/react,@nrwl/webetc).What might be helpful though is printing a banner after installing an empty workspace.
P.S: - I got here through #2987, which was closed as a duplicate of this one
Thank you all for your answers, time and help.
So, the hell. I investigated in order to set up a small project outside of mine to reproduce the issue but I didn’t reach to.
Finally, I can tell that the only thing that differs between one of my closest “working/not working” cases is the way the container is managed. In my final setup, the image is built by Kaniko and run inside a K8S cluster where the Nx workspace is created in a mounted volume, provisioned by NFS. To investigate further I now need to integrate this docker orchestration mechanism in the minimal example I began and I will not have time, neither need to: as a workaround I now create the workspace inside a not mounted volume and then copy it in the volume (like this: it works… 🤯).
My project was working since a while and as the unexpected error seems to come from Nx, I posted here. It seems that it is more complex than it seemed to so please forgive me for the lost of time induced on your side… You one more time proved that the Nx team/community is awesome ❤️ .
@hadrien-toma I’m happy to take a look if you’re able to isolate it in Docker 😃
This is how tmp package.json looks like when I run into this issue.
Seems to also be the case here https://github.com/nrwl/nx/issues/2987
While NX cli is still broken I was able to create new NX workspace with Angular CLI directly:
NOTE: I installed package
@nrwl/workspacevia NPM before executing the command above.