Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vitest for generator fails only when using nx test in freshly generated workspace #30283

Open
2 of 4 tasks
parker-norwood opened this issue Mar 6, 2025 · 0 comments
Open
2 of 4 tasks

Comments

@parker-norwood
Copy link

Current Behavior

npm config get registry in @nx/js's setupVerdaccio() throws an error in vitest tests only when running with nx.

Expected Behavior

Running vitest with nx doesn't cause tests to fail when they pass when executed with vitest directly.

GitHub Repo

https://github.com/parker-norwood/nx-bug-example

Steps to Reproduce

# 1. Generate a barebones ts workspace.
npx create-nx-workspace@latest org --preset ts --ci skip --formatter prettier && cd org/
# 2. Add @nx/plugin plugin
npx nx add @nx/plugin
# 3. Generate a plugin.
npx nx generate @nx/plugin:plugin --directory=tools/ --importPath=@org/tools --linter=eslint --name=tools --unitTestRunner=vitest --no-interactive
# 4. Generate a generator in the plugin.
npx nx generate @nx/plugin:generator --path=tools/src/generators/example/example --name=example --unitTestRunner=vitest --no-interactive
# 5. Extend the built-in @nx/js generator in this newly created generator.
# Example: https://nx.dev/extending-nx/recipes/local-generators
// tools/src/generators/example/example.ts
export async function exampleGenerator(
  tree: Tree,
  options: ExampleGeneratorSchema
) {
  const projectRoot = `packages/${options.name}`;
  libraryGenerator(tree, {
    directory: projectRoot,
    publishable: true,
    importPath: `@org/${options.name}`,
  });
  generateFiles(tree, path.join(__dirname, 'files'), projectRoot, options);
  await formatFiles(tree);
}
# 6. Run vitest, showing that the tests pass.
npx vitest run
 ✓ |@org/tools| src/generators/example/example.spec.ts (1) 646ms
   ✓ example generator (1) 646ms
     ✓ should run successfully 646ms

 Test Files  1 passed (1)
      Tests  1 passed (1)
   Start at  23:28:27
   Duration  1.87s (transform 34ms, setup 0ms, collect 131ms, tests 646ms, environment 231ms, prepare 359ms)
# 7. Run with nx, showing that the tests fail. (failure logs below)
npx nx test @org/tools

Nx Report

NX   Report complete - copy this into the issue template

Node           : 22.14.0
OS             : linux-x64
Native Target  : x86_64-linux
npm            : 11.2.0

nx                 : 20.4.6
@nx/js             : 20.4.6
@nx/jest           : 20.4.6
@nx/eslint         : 20.4.6
@nx/workspace      : 20.4.6
@nx/devkit         : 20.4.6
@nx/eslint-plugin  : 20.4.6
@nx/plugin         : 20.4.6
@nx/vite           : 20.4.6
@nx/web            : 20.4.6
typescript         : 5.7.3
---------------------------------------
Registered Plugins:
@nx/js/typescript
@nx/eslint/plugin
@nx/vite/plugin
---------------------------------------
Local workspace plugins:
         @org/tools

Failure Logs

> nx run @org/tools:test

> vitest

The CJS build of Vite's Node API is deprecated. See https://vite.dev/guide/troubleshooting.html#vite-cjs-node-api-deprecated for more details.

 RUN  v1.6.1 /home/user/git/_temp/org/tools

 ❯ src/generators/example/example.spec.ts (1)
   ❯ example generator (1)
     ⠹ should run successfully
 ❯ src/generators/example/example.spec.ts (1) 547ms
   ❯ example generator (1) 547ms
     × should run successfully 547ms

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Failed Tests 1 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯

 FAIL  src/generators/example/example.spec.ts > example generator > should run successfully
Error: Command failed: npm config get registry
npm error code ENOWORKSPACES
npm error This command does not support workspaces.
npm error A complete log of this run can be found in: /home/user/.npm/_logs/2025-03-06T04_32_52_511Z-debug-0.log

 ❯ checkExecSyncError node:child_process:882:11
 ❯ execSync node:child_process:954:15
 ❯ setupVerdaccio ../node_modules/@nx/js/src/generators/setup-verdaccio/generator.js:12:61
 ❯ releaseTasks ../node_modules/@nx/js/src/generators/library/utils/add-release-config.js:130:73
 ❯ libraryGeneratorInternal ../node_modules/@nx/js/src/generators/library/library.js:150:64
 ❯ Proxy.libraryGenerator ../node_modules/@nx/js/src/generators/library/library.js:29:12
 ❯ Module.exampleGenerator [as default] src/generators/example/example.ts:15:3
     13| ) {
     14|   const projectRoot = `packages/${options.name}`;
     15|   await libraryGenerator(tree, {
       |   ^
     16|     directory: projectRoot,
     17|     publishable: true,
 ❯ src/generators/example/example.spec.ts:16:5

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
Serialized Error: { status: 1, signal: null, output: [ null, { type: 'Buffer', data: [] }, { type: 'Buffer', data: [ 110, 112, 109, 32, 101, 114, 114, 111, 114, 32, 99, 111, 100, 101, 32, 69, 78, 79, 87, 79, 82, 75, 83, 80, 65, 67, 69, 83, 10, 110, 112, 109, 32, 101, 114, 114, 111, 114, 32, 84, 104, 105, 115, 32, 99, 111, 109, 109, 97, 110, 100, 32, 100, 111, 101, 115, 32, 110, 111, 116, 32, 115, 117, 112, 112, 111, 114, 116, 32, 119, 111, 114, 107, 115, 112, 97, 99, 101, 115, 46, 10, 110, 112, 109, 32, 101, 114, 114, 111, 114, 32, 65, 32, 99, 111, 109, 112, 108, 101, 116, 101, 32, 108, 111, 103, 32, 111, 102, 32, 116, 104, 105, 115, 32, 114, 117, 110, 32, 99, 97, 110, 32, 98, 101, 32, 102, 111, 117, 110, 100, 32, 105, 110, 58, 32, 47, 104, 111, 109, 101, 47, 112, 97, 114, 107, 101, 114, 47, 46, 110, 112, 109, 47, 95, 108, 111, 103, 115, 47, 50, 48, 50, 53, 45, 48, 51, 45, 48, 54, 84, 48, 52, 95, 51, 50, 95, 53, 50, 95, 53, 49, 49, 90, 45, 100, 101, 98, 117, 103, 45, 48, 46, 108, 111, 103, 10 ] } ], pid: 131802, stdout: { type: 'Buffer', data: [] }, stderr: { type: 'Buffer', data: [ 110, 112, 109, 32, 101, 114, 114, 111, 114, 32, 99, 111, 100, 101, 32, 69, 78, 79, 87, 79, 82, 75, 83, 80, 65, 67, 69, 83, 10, 110, 112, 109, 32, 101, 114, 114, 111, 114, 32, 84, 104, 105, 115, 32, 99, 111, 109, 109, 97, 110, 100, 32, 100, 111, 101, 115, 32, 110, 111, 116, 32, 115, 117, 112, 112, 111, 114, 116, 32, 119, 111, 114, 107, 115, 112, 97, 99, 101, 115, 46, 10, 110, 112, 109, 32, 101, 114, 114, 111, 114, 32, 65, 32, 99, 111, 109, 112, 108, 101, 116, 101, 32, 108, 111, 103, 32, 111, 102, 32, 116, 104, 105, 115, 32, 114, 117, 110, 32, 99, 97, 110, 32, 98, 101, 32, 102, 111, 117, 110, 100, 32, 105, 110, 58, 32, 47, 104, 111, 109, 101, 47, 112, 97, 114, 107, 101, 114, 47, 46, 110, 112, 109, 47, 95, 108, 111, 103, 115, 47, 50, 48, 50, 53, 45, 48, 51, 45, 48, 54, 84, 48, 52, 95, 51, 50, 95, 53, 50, 95, 53, 49, 49, 90, 45, 100, 101, 98, 117, 103, 45, 48, 46, 108, 111, 103, 10 ] } }
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[1/1]⎯

 Test Files  1 failed (1)
      Tests  1 failed (1)
   Start at  23:32:50
   Duration  1.85s (transform 105ms, setup 0ms, collect 140ms, tests 547ms, environment 240ms, prepare 363ms)

Warning: command "vitest" exited with non-zero status code
—————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————

 NX   Ran target test for project @org/tools (2s)

   ✖  1/1 failed
   ✔  0/1 succeeded [0 read from cache]

Package Manager Version

npm 11.2.0

Operating System

  • macOS
  • Linux
  • Windows
  • Other (Please specify)

Additional Information

I also tested this earlier with version 20.5.0-rc.2 and the same thing occurred.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant