nrwl / nx

Smart Monorepos · Fast CI
https://nx.dev
MIT License
23.63k stars 2.36k forks source link

Problem testing simple package in repo #8222

Closed mwoodpatrick closed 2 years ago

mwoodpatrick commented 2 years ago

I'm trying to follow the guide:

Nx and Yarn/Lerna (Workspaces for Publishing NPM Packages)

Current Behavior

I was able to create the simple project and install the projects dependencies but when I try to run:

npx nx test simple

I get:

Usage Error: The project in /mnt/wsl/projects/git/www/my-payload/package.json doesn't seem to have been installed - running an install there might help

$ yarn run [--inspect] [--inspect-brk] [-T,--top-level] [-B,--binaries-only] <scriptName> ...

———————————————————————————————————————————————

>  NX   ERROR  Running target "simple:test" failed

  Failed tasks:

  - simple:test

  Hint: run the command with --verbose for more details.

If I cd into the packages/simple directory and run:

nodeindex.js`

The test runs normally and displays:

Hello World

Expected Behavior

Running the above nx command should run node and display the expected output

Steps to Reproduce

Not sure AFAIK I'm Just following the setup in the guide, any suggestions on how I can debug what I've done wrong would be appreciated.

I have a public repo of my code here:

https://github.com/mwoodpatrick/my-payload

Failure Logs

No logs generated

Environment

The only special item of notice is that I'm running on WSL-2 but I have other nx projects running in same environment without issue.

NX Report complete - copy this into the issue template

Node : 16.13.1 OS : linux x65 yarn : 3.1.1

nx : 13.3.9 @nrwl/angular : undefined @nrwl/cli : 13.3.9 @nrwl/cypress : undefined @nrwl/devkit : 13.3.9 @nrwl/eslint-plugin-nx : undefined @nrwl/express : undefined @nrwl/jest : 13.3.9 @nrwl/linter : 13.3.9 @nrwl/nest : undefined @nrwl/next : undefined @nrwl/node : undefined @nrwl/nx-cloud : undefined @nrwl/react : undefined @nrwl/react-native : undefined @nrwl/schematics : undefined @nrwl/tao : 13.3.9 @nrwl/web : undefined @nrwl/workspace : 13.3.9 @nrwl/storybook : undefined @nrwl/gatsby : undefined typescript : 4.4.4 rxjs : 6.6.7

Community plugins:

mwoodpatrick commented 2 years ago

This seems to be a yarn version issue with having yarn 3 set in my env even though I have a yarnrc.yml with:

nodeLinker: node-modules

yarnPath: .yarn/releases/yarn-1.23.0-20211217.1235.cjs

It would be great if nx supported yarn3

mwoodpatrick commented 2 years ago

Running the same project in a different wsl distribution which has yarn 1 as the default fixed the above issue.

Adding the complex project with a dependency on simple. Looks like I need to add version numbers to simple & complex packages for workspaces to pick these up and link them into node_modules otherwise yarn reports:

warning Missing version in workspace at "/mnt/wsl/projects/git/www/my-payload/packages/complex", ignoring.
warning Missing version in workspace at "/mnt/wsl/projects/git/www/my-payload/packages/simple", ignoring.

I did not see where in the guide it discusses this.

Adding the version numbers, then running yarn (not mentioned) fixes the problem (by linking the packages into node_modules and then

npx nx test complex

runs.

However, running:

npx nx dep-graph

Does not show the dependency of complex on simple even though its identified in the package.json and index.js

mwoodpatrick commented 2 years ago

running

npx nx run-many --target --test --all --parallel=5

as described in the guide fails for me with:

Not enough arguments following: target

However, running:

npx nx run-many --target=test --all --parallel=5

Does run the tests

mwoodpatrick commented 2 years ago

The same is true for:

npx nx affected --target --test --all

Changing this to:

npx nx affected --target=test --all

The test runs as expectedf

mwoodpatrick commented 2 years ago

Doing:

yarn add -W -D @nrwl/node
npx nx g @nrwl/node:application my-node-app

Puts the node app my-node-app under packages rather than apps which is what I had expected!

github-actions[bot] commented 1 year ago

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.