Nx: Cannot create a new workspace

Created on 3 Sep 2019  ·  4Comments  ·  Source: nrwl/nx

_Update: it worked if I installed yarn, which means the npm use case might have a bug? I will use yarn to get through the tutorial but would love to have it work with npm as that's mostly what we use here at my company! :)_

Hi team! I just recently heard about nx and wanted to understand what it was, so I've been trying to go through the react tutorial today. Unfortunately, I cannot get nx or workspace creation to work.

Expected Behavior

When running: npx create-nx-workspace@latest test
I expect to have a new workspace and the ability to continue working through the react baed workspace tutorial. 🌱

Current Behavior

I cannot create a workspace.

Failure Information (for bugs)

Steps to Reproduce

Run: npx create-nx-workspace@latest test
Choose: empty
Choose: Nx

Results in:

❯ npx create-nx-workspace@latest test   
npx: installed 165 in 12.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...
added 162 packages from 129 contributors and audited 433 packages in 6.61s
found 0 vulnerabilities

new test --preset="empty" --collection=@nrwl/workspace
/bin/sh: yarn: command not found
Package install failed, see above.
(node:92037) UnhandledPromiseRejectionWarning: Error: Command failed: "/var/folders/0x/pp76v0d94cv32x36gv5jkf1w0000gr/T/tmp-92037xpXJ1wm9P305/node_modules/.bin/tao" new test --preset="empty" --collection=@nrwl/workspace
    at checkExecSyncError (child_process.js:621:11)
    at Object.execSync (child_process.js:657:15)
    at createApp (/Users/jspencer/.npm/_npx/92037/lib/node_modules/create-nx-workspace/bin/create-nx-workspace.js:310:21)
    at /Users/jspencer/.npm/_npx/92037/lib/node_modules/create-nx-workspace/bin/create-nx-workspace.js:60:21
    at processTicksAndRejections (internal/process/task_queues.js:85:5)
(node:92037) 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:92037) [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.

Node modules installed in temporary directory created by the create-workspace script:

/var/folders/0x/pp76v0d94cv32x36gv5jkf1w0000gr/T/tmp-92037xpXJ1wm9P305/node_modules
❯ ls
@angular-devkit              get-stream                   mute-stream                  shebang-command
@nrwl                        graceful-fs                  nice-try                     shebang-regex
ajv                          graphviz                     normalize-package-data       shell-quote
ansi-escapes                 has                          npm-run-all                  signal-exit
ansi-regex                   has-flag                     npm-run-path                 source-map
ansi-styles                  has-symbols                  number-is-nan                sourcemap-codec
argparse                     hosted-git-info              object-inspect               spdx-correct
balanced-match               iconv-lite                   object-keys                  spdx-exceptions
brace-expansion              ignore                       onetime                      spdx-expression-parse
camelcase                    inquirer                     opn                          spdx-license-ids
chalk                        invert-kv                    os-locale                    sprintf-js
chardet                      is-arrayish                  os-tmpdir                    string-width
cli-cursor                   is-callable                  p-finally                    string.prototype.padend
cli-width                    is-date-object               p-limit                      string.prototype.trimleft
cliui                        is-directory                 p-locate                     string.prototype.trimright
code-point-at                is-fullwidth-code-point      p-try                        strip-ansi
color-convert                is-promise                   parse-json                   strip-bom
color-name                   is-regex                     path-exists                  strip-eof
concat-map                   is-stream                    path-key                     strip-json-comments
cosmiconfig                  is-symbol                    path-parse                   supports-color
cross-spawn                  is-wsl                       path-type                    temp
decamelize                   isexe                        pidtree                      through
define-properties            js-yaml                      pify                         tmp
error-ex                     json-parse-better-errors     prettier                     tslib
es-abstract                  json-schema-traverse         pseudomap                    typescript
es-to-primitive              jsonfile                     punycode                     universalify
escape-string-regexp         lcid                         read-pkg                     uri-js
esprima                      load-json-file               require-directory            validate-npm-package-license
execa                        locate-path                  require-from-string          viz.js
external-editor              lodash                       require-main-filename        which
fast-deep-equal              lru-cache                    resolve                      which-module
fast-json-stable-stringify   magic-string                 restore-cursor               wrap-ansi
figures                      mem                          run-async                    y18n
find-up                      memorystream                 rxjs                         yallist
fs-extra                     mimic-fn                     safer-buffer                 yargs
function-bind                minimatch                    semver                       yargs-parser
get-caller-file              minimist                     set-blocking

I tried with the --ignore-existing flag: ❯ npx --ignore-existing create-nx-workspace@latest test

and got the same issue:

npx: installed 165 in 15.537s
? 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...
added 162 packages from 129 contributors and audited 433 packages in 7.226s
found 0 vulnerabilities

new test --preset="empty" --collection=@nrwl/workspace
/bin/sh: yarn: command not found
Package install failed, see above.
(node:92324) UnhandledPromiseRejectionWarning: Error: Command failed: "/var/folders/0x/pp76v0d94cv32x36gv5jkf1w0000gr/T/tmp-92324HmR6V2T4FB24/node_modules/.bin/tao" new test --preset="empty" --collection=@nrwl/workspace
    at checkExecSyncError (child_process.js:621:11)
    at Object.execSync (child_process.js:657:15)
    at createApp (/Users/jspencer/.npm/_npx/92324/lib/node_modules/create-nx-workspace/bin/create-nx-workspace.js:310:21)
    at /Users/jspencer/.npm/_npx/92324/lib/node_modules/create-nx-workspace/bin/create-nx-workspace.js:60:21
    at processTicksAndRejections (internal/process/task_queues.js:85:5)
(node:92324) 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:92324) [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.

Context

node version: 12.9.1
npm version: 6.11.2
yarn version: I do not have yarn installed
ng version: I do not have the angular cli installed
nx version script failed, I installed it with npm i -g @nrwl/cli as instructed.

❯ nx --version
internal/modules/cjs/loader.js:775
    throw err;
    ^

Error: Cannot find module '/Users/jspencer/jmes/nx/test/node_modules/@nrwl/cli/bin/nx.js'
Require stack:
- /Users/jspencer/.nvm/versions/node/v12.9.1/lib/node_modules/@nrwl/cli/bin/nx.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:772:15)
    at Function.Module._load (internal/modules/cjs/loader.js:677:27)
    at Module.require (internal/modules/cjs/loader.js:830:19)
    at require (internal/modules/cjs/helpers.js:68:18)
    at Object.<anonymous> (/Users/jspencer/.nvm/versions/node/v12.9.1/lib/node_modules/@nrwl/cli/bin/nx.js:52:9)
    at Module._compile (internal/modules/cjs/loader.js:936:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:947:10)
    at Module.load (internal/modules/cjs/loader.js:790:32)
    at Function.Module._load (internal/modules/cjs/loader.js:703:12)
    at Function.Module.runMain (internal/modules/cjs/loader.js:999:10) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/Users/jspencer/.nvm/versions/node/v12.9.1/lib/node_modules/@nrwl/cli/bin/nx.js'
  ]
}

Other environment info with npx envinfo

  System:
    OS: macOS High Sierra 10.13.5
    CPU: (4) x64 Intel(R) Core(TM) i7-7660U CPU @ 2.50GHz
    Memory: 1.46 GB / 16.00 GB
    Shell: 5.3 - /bin/zsh
  Binaries:
    Node: 12.9.1 - ~/.nvm/versions/node/v12.9.1/bin/node
    npm: 6.11.2 - ~/.nvm/versions/node/v12.9.1/bin/npm
  Utilities:
    Make: 3.81 - /usr/bin/make
    GCC: 4.2.1 - /usr/bin/gcc
    Git: 2.20.1 - /usr/local/bin/git
  Servers:
    Apache: 2.4.33 - /usr/sbin/apachectl
  Virtualization:
    Docker: 19.03.1 - /usr/local/bin/docker
    VirtualBox: 5.2.20 - /usr/local/bin/vboxmanage
  IDEs:
    Emacs: 22.1.1 - /usr/bin/emacs
    Nano: 2.0.6 - /usr/bin/nano
    VSCode: 1.37.1 - /usr/local/bin/code
    Vim: 8.0 - /usr/bin/vim
    Xcode: /undefined - /usr/bin/xcodebuild
  Languages:
    Bash: 3.2.57 - /bin/bash
    Go: 1.11.5 - /usr/local/bin/go
    Elixir: 1.8.1 - /usr/local/bin/elixir
    Java: 1.8.0_202 - /usr/bin/javac
    Perl: 5.18.2 - /usr/bin/perl
    PHP: 7.1.16 - /usr/bin/php
    Python: 2.7.10 - /usr/bin/python
    Ruby: 2.5.1 - /Users/jspencer/.rbenv/shims/ruby
    Rust: 1.18.3 - /Users/jspencer/.cargo/bin/rustup
  Databases:
    SQLite: 3.19.3 - /usr/bin/sqlite3
  Browsers:
    Chrome: 76.0.3809.132
    Firefox Developer Edition: 69.0
    Safari: 11.1.1

Other

I don't know why the script is talking to yarn (/bin/sh: yarn: command not found). I picked apart your create-workspace script, tried determinePackageManager in isolation and it reported back npm. And it looks like the workspace script ouput above installs with npm but then tries to talk to yarn? Exciting!

Thanks!

bug

All 4 comments

I had the same issue with a fresh node install.

Seems like the problem is with detectPackageManager in the @nrwl/tao package :

https://github.com/nrwl/nx/blob/70d71b35167ba16a45e402c720468670df37b7e2/packages/tao/src/commands/generate.ts#L142-L157

host.exists is an Observable so this always returns 'yarn'

I'll look at putting a PR together.

While I've added a PR for this, I'm not comfortable with a lack of tests. Is there a good way to add some relevant unit tests?

(I'm also not super confident that the scope is really appropriate, but it's a short list of available options 🤷‍♀️)

Thank you everyone! I look forward to being able to create my first workspace 😎

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ZempTime picture ZempTime  ·  3Comments

markphip picture markphip  ·  3Comments

joelmuskwe picture joelmuskwe  ·  3Comments

zpydee picture zpydee  ·  3Comments

zachnewburgh picture zachnewburgh  ·  3Comments