Nx: Collection "@nrwl/workspace" cannot be resolved.

Created on 3 May 2020  Β·  42Comments  Β·  Source: nrwl/nx

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 > [email protected]: request has been deprecated, see https://github.com/request/request/issues/3142
warning " > @nrwl/[email protected]" 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

repro needed misc stale

Most helpful comment

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@latest and create an empty workspace.
The next suggested command fails nx generate @nrwl/react:application my-application with "Collection "@nrwl/react" cannot be resolved."

Running npm install @nrwl/react seems to have resolved the problem. Perhaps consider adding this to the tutorial if nx generate @nrwl/react:application is unable to install its own dependencies.

All 42 comments

While NX cli is still broken I was able to create new NX workspace with Angular CLI directly:

ng new selectable --collection=@nrwl/workspace

_NOTE:_ I installed package @nrwl/workspace via NPM before executing the command above.

Thank 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/workspace globally, I would like to stay on locally installed package to prevent permissions issues (and other architecture issues that will come with it).

Is this issue documented elsewhere? I am trying to create a workspace and also getting Collection "@nrwl/workspace" cannot be resolved. via npx create-nx-workspace@latest --ignore-existing.

Also installing @nrwl/workspace globally and running ng new selectable --collection=@nrwl/workspace resulted in the same error: An unhandled exception occurred: Collection "@nrwl/workspace" cannot be resolved.

node: v14.2.0
npm: 6.14.4

Can confirm, have this issue as well.

I'm on the same versions of npm and node as @collegeworking and don't run into the issue.

node: 14.2.0
npm: 16.14.4

When somebody runs into this issue can you print the contents of the package.json in the tmp directory that is printed in this log?

(node:847) UnhandledPromiseRejectionWarning: Error: Command failed: "/tmp/tmp-84746viJAJvJms6/node_modules/.bin/ng" new

/tmp/tmp-84746viJAJvJms6/package.json

Here is the content of it:

OCI runtime exec failed: exec failed: container_linux.go:349: starting container process caused "exec: \"bash\": executable file not found in $PATH": unknown
/ $ cat /tmp/tmp-625ap2qsTyxpS49/node_modules/.bin/ng
#!/usr/bin/env node
'use strict';

// Provide a title to the process in `ps`.
// Due to an obscure Mac bug, do not start this title with any symbol.
try {
  process.title = 'ng ' + Array.from(process.argv).slice(2).join(' ');
} catch (_) {
  // If an error happened above, use the most basic title.
  process.title = 'ng';
}

// This node version check ensures that extremely old versions of node are not used.
// These may not support ES2015 features such as const/let/async/await/etc.
// These would then crash with a hard to diagnose error message.
// tslint:disable-next-line: no-var-keyword
var version = process.versions.node.split('.').map(part => Number(part));
if (version[0] < 10 || version[0] === 11 || (version[0] === 10 && version[1] < 13)) {
  console.error(
    'Node.js version ' + process.version + ' detected.\n' +
    'The Angular CLI requires a minimum Node.js version of either v10.13 or v12.0.\n\n' +
    'Please update your Node.js version or visit https://nodejs.org/ for additional instructions.\n'
  );

  process.exitCode = 3;
} else {
  require('../lib/init');
}
/ $ 

@FrozenPandaz to reproduce the issue, I connect to a new Docker node:alpine container and run the command I described in it, the issue happens systematically on my side.

Seems to also be the case here https://github.com/nrwl/nx/issues/2987

I'm on the same versions of npm and node as @collegeworking and don't run into the issue.

node: 14.2.0
npm: 16.14.4

When somebody runs into this issue can you print the contents of the package.json in the tmp directory that is printed in this log?

(node:847) UnhandledPromiseRejectionWarning: Error: Command failed: "/tmp/tmp-84746viJAJvJms6/node_modules/.bin/ng" new

/tmp/tmp-84746viJAJvJms6/package.json

{
  "dependencies": {
    "@nrwl/workspace": "9.3.0",
    "@angular/cli": "~9.1.0",
    "typescript": "~3.8.3",
    "prettier": "2.0.4"
  },
  "license": "MIT"
}

This is how tmp package.json looks like when I run into this issue.

@FrozenPandaz @levani132 - I can confirm that my output is identical as well

  1. npx create-nx-workspace workspace
  2. choose empty workspace
  3. choose nx cli
 ✘ ξ‚° ~/dev/node ξ‚° npx create-nx-workspace workspace
npx: installed 198 in 13.673s
? What to create in the new workspace empty             [an empty workspace]
? CLI to power the Nx workspace       Nx           [Extensible CLI for JavaScript and TypeScript applications]
Creating a sandbox with Nx...
[---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------] 0/364
new workspace --preset="empty" --interactive=false --collection=@nrwl/workspace
Collection "@nrwl/workspace" cannot be resolved.
(node:25837) UnhandledPromiseRejectionWarning: Error: Command failed: "/var/folders/g0/c7qwk52n1k5b20vy4sy9gdqm0000gn/T/tmp-25837YINyxEjsQZxz/node_modules/.bin/tao" new workspace --preset="empty" --interactive=false --collection=@nrwl/workspace
    at checkExecSyncError (child_process.js:621:11)
    at Object.execSync (child_process.js:658:15)
    at createApp (/Users/foo/.npm/_npx/25837/lib/node_modules/create-nx-workspace/bin/create-nx-workspace.js:343:21)
    at /Users/foo/.npm/_npx/25837/lib/node_modules/create-nx-workspace/bin/create-nx-workspace.js:76:21
    at processTicksAndRejections (internal/process/task_queues.js:89:5)
(node:25837) 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(). (rejection id: 1)
(node:25837) [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.

cat /var/folders/g0/c7qwk52n1k5b20vy4sy9gdqm0000gn/T/tmp-25837YINyxEjsQZxz/package.json

{"dependencies":{"@nrwl/workspace":"9.3.0","@nrwl/tao":"9.3.0","typescript":"~3.8.3","prettier":"2.0.4"},"license":"MIT"}%

And are there node modules in that directory? Is there a lock file? What happens if you run npm i or yarn in that tmp directory? Does @nrwl/workspace appear in the node modules directory?

So I went to a new machine (relatively same setup - Win 10 64bit) checked the node and npm version which were outdated and rather than install nvm which I was using on my other machine I used the node installer directly from the website. I would suggest anyone to try fully uninstall node, clear any npm cache and re-install via the installer then try again.

After doing that I again installed with versions:

C:\Users\XPS\Documents\code>node -v
v14.2.0

C:\Users\XPS\Documents\code>npm -v
6.14.4

and it worked for me.

Complete commands and output are below.

C:\Users\XPS\Documents\code>npx create-nx-workspace workspace
npx: installed 198 in 116.36s
? What to create in the new workspace angular           [a workspace with a single Angular application]
? Application name                    test-app
? Default stylesheet format           SASS(.scss)  [ http://sass-lang.com   ]
Creating a sandbox with Nx...
? Would you like to share anonymous usage data with the Angular Team at Google under
? Would you like to share anonymous usage data with the Angular Team at Google under
Google’s Privacy Policy at https://policies.google.com/privacy? For more details and
how to change this setting, see http://angular.io/analytics. No
added 401 packages from 239 contributors and audited 401 packages in 180.306s

23 packages are looking for funding
  run `npm fund` for details

found 4 low severity vulnerabilities
  run `npm audit fix` to fix them, or `npm audit` for details
new workspace --preset="angular" --appName="test-app" --style="scss" --interactive=false --collection=@nrwl/workspace
CREATE workspace/nx.json (462 bytes)
CREATE workspace/tsconfig.json (509 bytes)
CREATE workspace/package.json (1186 bytes)
CREATE workspace/README.md (2694 bytes)



√ Packages installed successfully.
√ Packages installed successfully.

There is a yarn.lock file yarn.lock.txt

(even after I uninstalled yarn and tried again, it is still using yarn.lock - then I reinstalled yarn and tried again with same results)

running yarn install says already up-to-date.

Here's a list of the folders in the node_modules directory

@angular-devkit
@nrwl
@types
ajv
ansi-escapes
ansi-regex
ansi-styles
argparse
axios
balanced-match
brace-expansion
camelcase
chalk
chardet
cli-cursor
cli-spinners
cli-width
cliui
clone
code-point-at
color-convert
color-name
concat-map
cosmiconfig
create-nx-workspace
cross-spawn
debug
decamelize
defaults
define-properties
end-of-stream
error-ex
es-abstract
es-to-primitive
escape-string-regexp
esprima
execa
external-editor
fast-deep-equal
fast-json-stable-stringify
fast-levenshtein
figures
find-up
follow-redirects
fs-extra
function-bind
get-caller-file
get-stream
graceful-fs
has
has-flag
has-symbols
hasha
hosted-git-info
iconv-lite
ignore
inquirer
invert-kv
is-arrayish
is-callable
is-date-object
is-directory
is-fullwidth-code-point
is-interactive
is-regex
is-stream
is-symbol
is-wsl
isexe
js-yaml
json-parse-better-errors
json-schema-traverse
jsonfile
lcid
load-json-file
locate-path
lodash
log-symbols
magic-string
map-age-cleaner
mem
memorystream
mimic-fn
minimatch
minimist
ms
mute-stream
nice-try
normalize-package-data
npm-run-all
npm-run-path
number-is-nan
object-inspect
object-keys
object.assign
once
onetime
opn
ora
os-locale
os-tmpdir
p-defer
p-finally
p-is-promise
p-limit
p-locate
p-try
parse-json
path-exists
path-key
path-parse
path-type
pidtree
pify
prettier
pump
punycode
read-pkg
require-directory
require-from-string
require-main-filename
resolve
restore-cursor
run-async
rxjs
safer-buffer
semver
set-blocking
shebang-command
shebang-regex
shell-quote
signal-exit
source-map
sourcemap-codec
spdx-correct
spdx-exceptions
spdx-expression-parse
spdx-license-ids
sprintf-js
string-width
string.prototype.padend
string.prototype.trimend
string.prototype.trimleft
string.prototype.trimright
string.prototype.trimstart
strip-ansi
strip-bom
strip-eof
strip-json-comments
supports-color
through
tmp
tslib
type-fest
typescript
universalify
uri-js
validate-npm-package-license
wcwidth
which
which-module
wrap-ansi
wrappy
y18n
yargs
yargs-parser

Not sure if this provides anything useful, but when I tried to install with --verbose, there are a few extra log lines shown.

 ~/dev/node ξ‚° npx create-nx-workspace workspace --verbose
npx: installed 198 in 15.803s
? What to create in the new workspace empty             [an empty workspace]
? CLI to power the Nx workspace       Nx           [Extensible CLI for JavaScript and TypeScript applications]
Creating a sandbox with Nx...
[#############################################################################################################################################################################################################] 364/364
new workspace "--verbose" --preset="empty" --interactive=false --collection=@nrwl/workspace
Collection "@nrwl/workspace" cannot be resolved.
Error: Collection "@nrwl/workspace" cannot be resolved.
    at NodeModulesEngineHost.resolve (/private/var/folders/g0/c7qwk52n1k5b20vy4sy9gdqm0000gn/T/tmp-45943dkceEsFE5jJw/node_modules/@angular-devkit/schematics/tools/node-module-engine-host.js:74:19)
    at NodeModulesEngineHost._resolveCollectionPath (/private/var/folders/g0/c7qwk52n1k5b20vy4sy9gdqm0000gn/T/tmp-45943dkceEsFE5jJw/node_modules/@angular-devkit/schematics/tools/node-module-engine-host.js:79:37)
    at NodeModulesEngineHost.createCollectionDescription (/private/var/folders/g0/c7qwk52n1k5b20vy4sy9gdqm0000gn/T/tmp-45943dkceEsFE5jJw/node_modules/@angular-devkit/schematics/tools/file-system-engine-host-base.js:109:27)
    at SchematicEngine._createCollectionDescription (/private/var/folders/g0/c7qwk52n1k5b20vy4sy9gdqm0000gn/T/tmp-45943dkceEsFE5jJw/node_modules/@angular-devkit/schematics/src/engine/engine.js:147:40)
    at SchematicEngine.createCollection (/private/var/folders/g0/c7qwk52n1k5b20vy4sy9gdqm0000gn/T/tmp-45943dkceEsFE5jJw/node_modules/@angular-devkit/schematics/src/engine/engine.js:140:43)
    at getCollection (/private/var/folders/g0/c7qwk52n1k5b20vy4sy9gdqm0000gn/T/tmp-45943dkceEsFE5jJw/node_modules/@nrwl/tao/src/commands/generate.js:174:40)
    at Object.<anonymous> (/private/var/folders/g0/c7qwk52n1k5b20vy4sy9gdqm0000gn/T/tmp-45943dkceEsFE5jJw/node_modules/@nrwl/tao/src/commands/generate.js:276:32)
    at Generator.next (<anonymous>)
    at fulfilled (/private/var/folders/g0/c7qwk52n1k5b20vy4sy9gdqm0000gn/T/tmp-45943dkceEsFE5jJw/node_modules/@nrwl/tao/src/commands/generate.js:5:58)
(node:45943) UnhandledPromiseRejectionWarning: Error: Command failed: "/var/folders/g0/c7qwk52n1k5b20vy4sy9gdqm0000gn/T/tmp-45943dkceEsFE5jJw/node_modules/.bin/tao" new workspace "--verbose" --preset="empty" --interactive=false --collection=@nrwl/workspace
    at checkExecSyncError (child_process.js:621:11)
    at Object.execSync (child_process.js:658:15)
    at createApp (/Users/aturner/.npm/_npx/45943/lib/node_modules/create-nx-workspace/bin/create-nx-workspace.js:343:21)
    at /Users/aturner/.npm/_npx/45943/lib/node_modules/create-nx-workspace/bin/create-nx-workspace.js:76:21
    at processTicksAndRejections (internal/process/task_queues.js:89:5)
(node:45943) 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(). (rejection id: 1)
(node:45943) [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.

@FrozenPandaz On my side, here is the content of the package.json:

{"dependencies":{"@nrwl/workspace":"9.3.0","@angular/cli":"~9.1.0","typescript":"~3.8.3","prettier":"2.0.4"},"license":"MIT"}/tmp/tmp-6253z1jvyjWkHqf $ 

And here the result of the execution of cat yarn.lock | grep nrwl:

"@nrwl/[email protected]":
  resolved "https://registry.yarnpkg.com/@nrwl/cli/-/cli-9.3.0.tgz#5d54625be09dd72a9b3458749ea88103794986c9"
    "@nrwl/tao" "9.3.0"
"@nrwl/[email protected]":
  resolved "https://registry.yarnpkg.com/@nrwl/tao/-/tao-9.3.0.tgz#04ac3de1276838eda59c4ebfccf53baec00aab7d"
"@nrwl/[email protected]":
  resolved "https://registry.yarnpkg.com/@nrwl/workspace/-/workspace-9.3.0.tgz#faf47aab20e6f8515853fb0997bc92bdb86ac3ed"
    "@nrwl/cli" "9.3.0"

And yes: there is a node_modules in the directory (and it is not empty nor seems weird)

@FrozenPandaz On my side, here is the content of the package.json:

{"dependencies":{"@nrwl/workspace":"9.3.0","@angular/cli":"~9.1.0","typescript":"~3.8.3","prettier":"2.0.4"},"license":"MIT"}/tmp/tmp-6253z1jvyjWkHqf $ 

And here the result of the execution of cat yarn.lock | grep nrwl:

"@nrwl/[email protected]":
  resolved "https://registry.yarnpkg.com/@nrwl/cli/-/cli-9.3.0.tgz#5d54625be09dd72a9b3458749ea88103794986c9"
    "@nrwl/tao" "9.3.0"
"@nrwl/[email protected]":
  resolved "https://registry.yarnpkg.com/@nrwl/tao/-/tao-9.3.0.tgz#04ac3de1276838eda59c4ebfccf53baec00aab7d"
"@nrwl/[email protected]":
  resolved "https://registry.yarnpkg.com/@nrwl/workspace/-/workspace-9.3.0.tgz#faf47aab20e6f8515853fb0997bc92bdb86ac3ed"
    "@nrwl/cli" "9.3.0"

And yes: there is a node_modules in the directory (and it is not empty nor seems weird)

Yeah, almost same with me, only difference is that I don't have yarn.lock, I have package-lock.json and it looks like this:

Pastebin

I was able to get a new build working.

tldr; I upgraded node from v12.3.1 to v12.16.3, which broke existing v9 nx projects but allowed me to create new projects successfully

I had an existing project that worked, but I could not use any generate CLI commands or create new projects because of the invalid collection error. Then I ran npm run build and got the following error:

Node version v12.3.1 is not supported. Supported range is "10 || >=12.9".

Then, after I upgraded node to v12.16.3, my existing project was broken.

Any time I tried tobuild or start I was getting this error:

Must use import to load ES Module: /Users/foo/dev/node/sftools/node_modules/is-promise/index.js
require() of ES modules is not supported.
require() of /Users/foo/dev/node/sftools/node_modules/is-promise/index.js from /Users/foo/dev/node/sftools/node_modules/run-async/index.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
Instead rename /Users/foo/dev/node/sftools/node_modules/is-promise/index.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /Users/foo/dev/node/sftools/node_modules/is-promise/package.json.

I deleted my node_modules folder and re-installed the dependencies, but got the same error.

But, now I am able to generate new projects without the collection error that I was receiving previously. (below shows an empty nx workspace, but I can confirm react+express was successfully generated as well)

 ~/dev/node ξ‚° npx create-nx-workspace@latest nx-test-100
npx: installed 198 in 10.982s
? What to create in the new workspace empty             [an empty workspace]
? CLI to power the Nx workspace       Nx           [Extensible CLI for JavaScript and TypeScript applications]
Creating a sandbox with Nx...
[#####################################################################################################################################################################] 364/364
warning Your current version of Yarn is out of date. The latest version is "1.22.4", while you're on "1.16.0".
new nx-test-100 --preset="empty" --interactive=false --collection=@nrwl/workspace
βœ” Packages installed successfully.
    Successfully initialized git.
CREATE nx-test-100/nx.json (466 bytes)
CREATE nx-test-100/tsconfig.json (509 bytes)
CREATE nx-test-100/README.md (2543 bytes)
CREATE nx-test-100/.editorconfig (245 bytes)
CREATE nx-test-100/.gitignore (503 bytes)
CREATE nx-test-100/.prettierignore (74 bytes)
CREATE nx-test-100/.prettierrc (26 bytes)
CREATE nx-test-100/workspace.json (1130 bytes)
CREATE nx-test-100/package.json (1103 bytes)
CREATE nx-test-100/apps/.gitkeep (1 bytes)
CREATE nx-test-100/libs/.gitkeep (0 bytes)
CREATE nx-test-100/tools/tsconfig.tools.json (218 bytes)
CREATE nx-test-100/tools/schematics/.gitkeep (0 bytes)
CREATE nx-test-100/.vscode/extensions.json (109 bytes)

Thank you all for providing the details.

I copied the yarn.lock that @paustint and the package-lock.json that @levani132 posted and still did not run into the issue. :confused:

Sorry all, perhaps the Community Slack may be able to help?

@FrozenPandaz I can systematically reproduce this issue in a fresh docker container (node:alpine). Do you need help to reproduce it in Docker?

@hadrien-toma I'm happy to take a look if you're able to isolate it in Docker :)

I tried replicating in a docker and was unsuccessful. Can you post your Dockerfile please?

This is mine:

Dockerfile:

FROM node:alpine

RUN npx create-nx-workspace@latest my-ws --preset=empty --cli=nx

Logs:

❯ sudo docker build ./ --no-cache                                                                                                                                                          ─╯
Sending build context to Docker daemon  127.9MB
Step 1/2 : FROM node:alpine
 ---> 87c43f8d8077
Step 2/2 : RUN npx create-nx-workspace@latest my-ws --preset=empty --cli=nx
 ---> Running in 0850e438d77d
npx: installed 198 in 11.393s
Creating a sandbox with Nx...
new my-ws --preset="empty" --interactive=false --collection=@nrwl/workspace
- Installing packages...
βœ” Packages installed successfully.
/bin/sh: git: not found
CREATE my-ws/nx.json (460 bytes)
CREATE my-ws/tsconfig.json (509 bytes)
CREATE my-ws/README.md (2532 bytes)
CREATE my-ws/.editorconfig (245 bytes)
CREATE my-ws/.gitignore (503 bytes)
CREATE my-ws/.prettierignore (74 bytes)
CREATE my-ws/.prettierrc (26 bytes)
CREATE my-ws/workspace.json (1130 bytes)
CREATE my-ws/package.json (1097 bytes)
CREATE my-ws/apps/.gitkeep (1 bytes)
CREATE my-ws/libs/.gitkeep (0 bytes)
CREATE my-ws/tools/tsconfig.tools.json (218 bytes)
CREATE my-ws/tools/schematics/.gitkeep (0 bytes)
CREATE my-ws/.vscode/extensions.json (109 bytes)

β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”


>  NX   NOTE  Nx CLI is not installed globally.

  This means that you might have to use "yarn nx" or "npm nx" to execute commands in the workspace.
  Run "yarn global add @nrwl/cli" or "npm install -g @nrwl/cli" to be able to execute command directly.

Removing intermediate container 0850e438d77d
 ---> cadb1bef78d3
Successfully built cadb1bef78d3

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 :heart: .

Should we close the issue?

Not sure, I still need to find a way to make it work. Now that I've dived deeper into benefits of using nx for my company project(s) and also was able to migrate our project to nx, only some of my teammates have the issue described above and of course I don't want to lose those benefits just because of this small I guess system faults. And also not sure whether I should take this question to stackoverflow or not, since even if some specific systems fail to run the command, it means that, its source will need to be chnanged.

I also want to discuss something about affected changes which is somewhere between question and suggestion which I want to ask to either Victor or Panda or maybe let it be some other involved person. (Truth is that when 1 app has 10 libs and one lib is changed, whole app so even all the 10 lib is built too, I think we can optimize this if it isn't already). I know I shouldn't be asking this here so could you tell me where to ask it?

I'm here for the same issue.

I'm trying to eval nx after watching the videos with much excitement - but cannot get started... :sob:

I tried on my ubuntu 18, I tried in a docker, I tried with nx@8m with create-nx-workspace@8 - same results.

Here's from the docker:

{10:43}~/ βœ“ ➭ docker run -it node:alpine sh
/ # npm get registry
https://registry.npmjs.org/
/ # npx -v
6.14.5
/ # npm -v
6.14.5
/ # node -v
v14.4.0
/ # npx create-nx-workspace
npx: installed 197 in 21.497s
? Workspace name (e.g., org name)     eval-nx
? What to create in the new workspace empty             [an empty workspace with a layout that works best for building apps]
? CLI to power the Nx workspace       Nx           [Recommended for all applications (React, Node, etc..)]
? Use the free tier of the distributed cache provided by Nx Cloud? No  [Only use local computation cache]
Creating a sandbox with Nx...
[----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------] 0/362
new eval-nx --preset="empty" --interactive=false --collection=@nrwl/workspace
βœ” Packages installed successfully.
/bin/sh: git: not found
CREATE eval-nx/nx.json (511 bytes)
CREATE eval-nx/tsconfig.json (509 bytes)
CREATE eval-nx/README.md (3246 bytes)
CREATE eval-nx/.editorconfig (245 bytes)
CREATE eval-nx/.gitignore (503 bytes)
CREATE eval-nx/.prettierignore (74 bytes)
CREATE eval-nx/.prettierrc (26 bytes)
CREATE eval-nx/workspace.json (1130 bytes)
CREATE eval-nx/package.json (1099 bytes)
CREATE eval-nx/tools/tsconfig.tools.json (218 bytes)
CREATE eval-nx/tools/schematics/.gitkeep (0 bytes)
CREATE eval-nx/apps/.gitkeep (0 bytes)
CREATE eval-nx/libs/.gitkeep (0 bytes)

β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”


>  NX   NOTE  Nx CLI is not installed globally.

  This means that you might have to use "yarn nx" or "npm nx" to execute commands in the workspace.
  Run "yarn global add @nrwl/cli" or "npm install -g @nrwl/cli" to be able to execute command directly.

/ # npm i -g @nrwl/cli
/usr/local/bin/nx -> /usr/local/lib/node_modules/@nrwl/cli/bin/nx.js
+ @nrwl/[email protected]
added 124 packages from 99 contributors in 8.123s
/ # cd eval-nx/
/eval-nx # which nx
/usr/local/bin/nx
/eval-nx # nx generate @nrwl/web:app app
Collection "@nrwl/web" cannot be resolved.
/eval-nx # 

I couldn't even find a versions set that works... :open_mouth:

{11:01}~/Code ➭ docker run -it node:12-alpine sh 
/ # npx -v
6.14.4
/ # npm -v
6.14.4
/ # node -v
v12.18.0
/ # npx create-nx-workspace
npx: installed 197 in 15.92s
? Workspace name (e.g., org name)     eval-nx
? What to create in the new workspace empty             [an empty workspace with a layout that works best for building apps]
? CLI to power the Nx workspace       Nx           [Recommended for all applications (React, Node, etc..)]
? Use the free tier of the distributed cache provided by Nx Cloud? No  [Only use local computation cache]
Creating a sandbox with Nx...
[----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------] 0/362
new eval-nx --preset="empty" --interactive=false --collection=@nrwl/workspace
βœ” Packages installed successfully.
/bin/sh: git: not found
CREATE eval-nx/nx.json (511 bytes)
CREATE eval-nx/tsconfig.json (509 bytes)
CREATE eval-nx/README.md (3246 bytes)
CREATE eval-nx/.editorconfig (245 bytes)
CREATE eval-nx/.gitignore (503 bytes)
CREATE eval-nx/.prettierignore (74 bytes)
CREATE eval-nx/.prettierrc (26 bytes)
CREATE eval-nx/workspace.json (1130 bytes)
CREATE eval-nx/package.json (1099 bytes)
CREATE eval-nx/tools/tsconfig.tools.json (218 bytes)
CREATE eval-nx/tools/schematics/.gitkeep (0 bytes)
CREATE eval-nx/apps/.gitkeep (0 bytes)
CREATE eval-nx/libs/.gitkeep (0 bytes)

β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”


>  NX   NOTE  Nx CLI is not installed globally.

  This means that you might have to use "yarn nx" or "npm nx" to execute commands in the workspace.
  Run "yarn global add @nrwl/cli" or "npm install -g @nrwl/cli" to be able to execute command directly.

/ # cd eval-nx/
/eval-nx # npm i -g @nrwl/cli
/usr/local/bin/nx -> /usr/local/lib/node_modules/@nrwl/cli/bin/nx.js
+ @nrwl/[email protected]
added 124 packages from 99 contributors in 3.993s
/eval-nx # nx generate @nrwl/web:app
Collection "@nrwl/web" cannot be resolved.
/eval-nx # %                             

Here's trying nx@8

{11:03}~/Code ➭ docker run -it node:12-alpine sh
/ # npx -v
6.14.4
/ # npm -v
6.14.4
/ # npde -v
sh: npde: not found
/ # node -v
v12.18.0
/ # npx create-nx-workspace@8 eval-nx
npx: installed 168 in 14.282s
? What to create in the new workspace empty             [an empty workspace]
? CLI to power the Nx workspace       Nx           [Extensible CLI for JavaScript and TypeScript applications]
Creating a sandbox with Nx...
[----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------] 0/325
new eval-nx --preset="empty" --interactive=false --collection=@nrwl/workspace
[----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------] 0/499
/bin/sh: git: not found
CREATE eval-nx/nx.json (260 bytes)
CREATE eval-nx/tsconfig.json (509 bytes)
CREATE eval-nx/README.md (2536 bytes)
CREATE eval-nx/.editorconfig (245 bytes)
CREATE eval-nx/.gitignore (503 bytes)
CREATE eval-nx/.prettierignore (74 bytes)
CREATE eval-nx/.prettierrc (26 bytes)
CREATE eval-nx/workspace.json (1004 bytes)
CREATE eval-nx/package.json (1138 bytes)
CREATE eval-nx/apps/.gitkeep (1 bytes)
CREATE eval-nx/libs/.gitkeep (0 bytes)
CREATE eval-nx/tools/tsconfig.tools.json (218 bytes)
CREATE eval-nx/tools/schematics/.gitkeep (0 bytes)
CREATE eval-nx/.vscode/extensions.json (109 bytes)

β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”


>  NX   NOTE  Nx CLI is not installed globally.

  This means that you might have to use "yarn nx" or "npm nx" to execute commands in the workspace.
  Run "yarn global add @nrwl/cli" or "npm install -g @nrwl/cli" to be able to execute command directly.

/ # npm i -g @nrwl/cli
/usr/local/bin/nx -> /usr/local/lib/node_modules/@nrwl/cli/bin/nx.js
+ @nrwl/[email protected]
added 124 packages from 99 contributors in 4.963s
/ # cd eval-nx/
/eval-nx # nx generate @nrwl/web:app app
Could not find module "@nrwl/web" from "/eval-nx".
/eval-nx # cat package.json 
{
  "name": "eval-nx",
  "version": "0.0.0",
  "license": "MIT",
  "scripts": {
    "nx": "nx",
    "start": "nx serve",
    "build": "nx build",
    "test": "nx test",
    "lint": "nx workspace-lint && nx lint",
    "e2e": "nx e2e",
    "affected:apps": "nx affected:apps",
    "affected:libs": "nx affected:libs",
    "affected:build": "nx affected:build",
    "affected:e2e": "nx affected:e2e",
    "affected:test": "nx affected:test",
    "affected:lint": "nx affected:lint",
    "affected:dep-graph": "nx affected:dep-graph",
    "affected": "nx affected",
    "format": "nx format:write",
    "format:write": "nx format:write",
    "format:check": "nx format:check",
    "update": "nx migrate latest",
    "workspace-schematic": "nx workspace-schematic",
    "dep-graph": "nx dep-graph",
    "help": "nx help"
  },
  "private": true,
  "dependencies": {},
  "devDependencies": {
    "@nrwl/workspace": "8.12.11",
    "@types/node": "~8.9.4",
    "dotenv": "6.2.0",
    "ts-node": "~7.0.0",
    "tslint": "~5.11.0",
    "@babel/compat-data": "7.8.0",
    "eslint": "6.1.0",
    "typescript": "~3.5.3",
    "prettier": "1.18.2"
  }
}
/eval-nx # 

P.S: - I got here through #2987, which was closed as a duplicate of this one

Could be related to #3233 - I also linked a pull-request with a fix there.

Omg (!).
I just noted that nx@8 said something different than nx@9

I think the problem was because I asked for an empty workspace
and it comes without @nrwl/web - ok...
After npm i @nrwl/web I could nx generate @nrwl/web:app app1

In that case - I'd suggest making the error-message clearer, and add a call-to-action to npm i the 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 resolved from nx@9 sent me to the wrong places - as an nx beginner I don't know what it means by Collection. 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@8 said
Could not find module "@nrwl/web" from "/eval-nx".
which was barely close enough to the familiar Could not find module "@nrwl/web".

@osher you need to make sure you install @nrwl/web first, as mentioned in the docs.

Try this:

FROM node:12-alpine

# Install CLI globally
RUN npm install -g @nrwl/cli

# Go to workspace
WORKDIR /workspace

# Create app
RUN npx  create-nx-workspace eval-nx --preset=empty --cli=nx --nx-cloud=false

# Change to app dir
WORKDIR /workspace/eval-nx

# Add Nrwl Plugin
RUN npm install @nrwl/web

# Create app with plugin
RUN nx generate @nrwl/web:app app
docker build . -t nx-issue2953
docker run --rm -it nx-issue2953 nx serve

@beeman - yea, I eventually figured. See my prev comment about improving the message
Also - there's a consistency problem. One place you call it plugin (docs), in other place collection (err msg) - so there...

I'm also trying to join the community slack, but it does not let me in. Do I have to be invited?

Glad you found the issue!

I'm also trying to join the community slack, but it does not let me in. Do I have to be invited?

Yes, you can use this link!

https://join.slack.com/t/nrwlcommunity/shared_invite/zt-ffstv0dy-wM2b~sYa_X7R8wXN02l2kA

Omg (!).
I just noted that nx@8 said something different than nx@9

I think the problem was because I asked for an empty workspace
and it comes without @nrwl/web - ok...
After npm i @nrwl/web I could nx generate @nrwl/web:app app1

In that case - I'd suggest making the error-message clearer, and add a call-to-action to npm i the 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 resolved from nx@9 sent me to the wrong places - as an nx beginner I don't know what it means by Collection. 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@8 said
Could not find module "@nrwl/web" from "/eval-nx".
which was barely close enough to the familiar Could not find module "@nrwl/web".

Same for me after npm install @nrwl/angular --save
We might be in a mistake trying to generate applications with no schema installed for this in an empty workspace.
The CLI and the VS plugin make you feel like everything is out of the box even in an empty workspace.

This could be solved in a patch adding a suggestion to the error message.

Collection "@nrwl/workspace" cannot be resolved. Did you install "@nrwl/angular" ?

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/web etc).

What might be helpful though is printing a banner after installing an empty workspace.

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@latest and create an empty workspace.
The next suggested command fails nx generate @nrwl/react:application my-application with "Collection "@nrwl/react" cannot be resolved."

Running npm install @nrwl/react seems to have resolved the problem. Perhaps consider adding this to the tutorial if nx generate @nrwl/react:application is unable to install its own dependencies.

I'm getting this same error with npx create-nx-plugin.

I've traced it back to https://github.com/nrwl/nx/commit/100989eacb533afeb43fcd035274daf271c1ad29, adding resolvePaths to packages/tao/src/commands/generate.ts.

If you either comment out this line or amend it to resolvePaths: [process.cwd(), root, __dirname], it works. Not sure if this is the same issue as create-nx-workspace.

same error for me when using nx g @nrwl/angular:app (Collection "@nrwl/angular" cannot be resolved)
any tips?

same error for me when using nx g @nrwl/angular:app (Collection "@nrwl/angular" cannot be resolved)
any tips?

Did you install the package '@nrwl/angular'?

same error for me when using nx g @nrwl/angular:app (Collection "@nrwl/angular" cannot be resolved)
any tips?

Did you install the package '@nrwl/angular'?

Thanks a lot. it worked. i wonder why there is no mentions on this for empty workspaces.

I am getting this similar error when trying to run:

npx create-nx-plugin my-org --pluginName my-plugin

I am running this in a parent directory, expecting it to create an entirely new workspace called "my-org"

Here is the error:

$ npx create-nx-plugin nx-duro --pluginName nx-pulumi                                                                             [10:29:32]
npx: installed 193 in 7.87s
Creating a sandbox with Nx...
new nx-duro "--pluginName" "nx-pulumi" --preset=empty --collection=@nrwl/workspace
Collection "@nrwl/workspace" cannot be resolved.
(node:45442) UnhandledPromiseRejectionWarning: Error: Command failed: "/var/folders/fj/75j7561x6xvfyk2d5dlcks140000gn/T/tmp-45442guCDtvBL4jKT/node_modules/.bin/tao" new nx-duro "--pluginName" "nx-pulumi" --preset=empty --collection=@nrwl/workspace
    at checkExecSyncError (child_process.js:630:11)
    at Object.execSync (child_process.js:666:15)
    at createWorkspace (/Users/adamduro/.npm/_npx/45442/lib/node_modules/create-nx-plugin/bin/create-nx-plugin.js:51:21)
    at /Users/adamduro/.npm/_npx/45442/lib/node_modules/create-nx-plugin/bin/create-nx-plugin.js:157:9
(node:45442) 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:45442) [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.

This issue has been automatically marked as stale because it hasn't had any recent activity. It will be closed in 14 days if no further activity occurs.
If we missed this issue please reply to keep it active.
Thanks for being a part of the Nx community! πŸ™

For me after installing "npm install @nrwl/angular" it works

This issue has been automatically marked as stale because it hasn't had any recent activity. It will be closed in 14 days if no further activity occurs.
If we missed this issue please reply to keep it active.
Thanks for being a part of the Nx community! πŸ™

Was this page helpful?
0 / 5 - 0 ratings