nx icon indicating copy to clipboard operation
nx copied to clipboard

@nx/jest/plugin Option "displayName" must be of type issue

Open vivex opened this issue 11 months ago • 14 comments

Current Behavior

created monorepor with expo preset:

npx create-nx-workspace@latest --preset=expo --appName=my-app

Node version: v20.10.0

trying to start app using following command:

 nx run my-app:run-ios

Getting following error:

 NX   Unable to create nodes for apps/app-bp/jest.config.ts using plugin @nx/jest/plugin.


	 Inner Error: Error: ● Validation Error:

  Option "displayName" must be of type:
    array
  but instead received:
    string

  Example:
  {
    "displayName": [
      "test-config",
      {
        "color": "blue",
        "name": "test-config"
      }
    ]
  }

  Configuration Documentation:
  https://jestjs.io/docs/configuration


Because of the error the Nx daemon process has exited. The next Nx command is going to restart the daemon process.
If the error persists, please run "nx reset".

Expected Behavior

should spinup the app

GitHub Repo

No response

Steps to Reproduce

  1. Node version: v20.10.0 OS Macos 14.3 Beta (23D5033f) M2
  2. npx create-nx-workspace@latest --preset=expo --appName=my-app
  3. nx run my-app:run-ios

Nx Report

NX   Unable to create nodes for apps/app-bp/jest.config.ts using plugin @nx/jest/plugin.


	 Inner Error: Error: ● Validation Error:

  Option "displayName" must be of type:
    array
  but instead received:
    string

  Example:
  {
    "displayName": [
      "test-config",
      {
        "color": "blue",
        "name": "test-config"
      }
    ]
  }

  Configuration Documentation:
  https://jestjs.io/docs/configuration


Because of the error the Nx daemon process has exited. The next Nx command is going to restart the daemon process.
If the error persists, please run "nx reset".

Failure Logs

NX   Unable to create nodes for apps/app-bp/jest.config.ts using plugin @nx/jest/plugin.


	 Inner Error: Error: ● Validation Error:

  Option "displayName" must be of type:
    array
  but instead received:
    string

  Example:
  {
    "displayName": [
      "test-config",
      {
        "color": "blue",
        "name": "test-config"
      }
    ]
  }

  Configuration Documentation:
  https://jestjs.io/docs/configuration


Because of the error the Nx daemon process has exited. The next Nx command is going to restart the daemon process.
If the error persists, please run "nx reset".

Package Manager Version

10.2.3

Operating System

  • [X] macOS
  • [ ] Linux
  • [ ] Windows
  • [ ] Other (Please specify)

Additional Information

No response

vivex avatar Mar 24 '24 12:03 vivex

Using DisplayName type will allow you to proceed.

declare type DisplayName = {
  name: string;
  color: typeof ForegroundColor;
};

declare type ForegroundColor =
	| 'black'
	| 'red'
	| 'green'
	| 'yellow'
	| 'blue'
	| 'magenta'
	| 'cyan'
	| 'white'
	| 'gray'
	| 'grey'
	| 'blackBright'
	| 'redBright'
	| 'greenBright'
	| 'yellowBright'
	| 'blueBright'
	| 'magentaBright'
	| 'cyanBright'
	| 'whiteBright';

oqx avatar Mar 28 '24 14:03 oqx

I'm also running into this issue. Changing displayName to an array as suggested changes to error to should be a string or an object. No matter what type I use, the error persists.

eamon0989 avatar Mar 29 '24 14:03 eamon0989

@vivex Not sure why (cache of course) but, if you delete node_modules & .nx cache folder (then reinstall packages), that error may disappear for you too (as it did for me).

valeporti avatar Mar 30 '24 14:03 valeporti

Ah, for heavens sake why we have this issue in the first place. I mean come on...

jest.config.ts

import type { Config } from 'jest';

/* eslint-disable */
export default {
  displayName: 'backend',
  preset: '../../jest.preset.js',
  testEnvironment: 'node',
  transform: {
    '^.+\\.[tj]s$': [
      'ts-jest',
      { tsconfig: '<rootDir>/tsconfig.spec.json' },
    ],
  },
  moduleFileExtensions: ['ts', 'js', 'html'],
  coverageDirectory: '../../coverage/apps/backend',
} satisfies Config;

And with this, you can see it clearly that displayName cannot be an array but rather an object or string. So what's with this suggestion and error?

It is really annoying and frustrating since it appears 5 out of 10 times for me which means that I cannot really rely and leverage Nx's full power by pipelining different commands, it really slows us down...

kasir-barati avatar Mar 31 '24 02:03 kasir-barati

I'm suffering the same problem. It seems related to the cache because when you execute the nx reset command it fixes the problem.

dario-rodriguez avatar Mar 31 '24 15:03 dario-rodriguez

@dario-rodriguez I just reset cache and solved it. This is really frustrating. Slowing me down because I am now not sure what is wrong.

blaqueMani avatar Apr 01 '24 19:04 blaqueMani

@vivex Not sure why (cache of course) but, if you delete node_modules & .nx cache folder (then reinstall packages), that error may disappear for you too (as it did for me).

It helped me!

"@nx/jest": "18.2.2", Your repository uses a higher version of Nx (18.2.2) than your global CLI version (17.0.2)

darius-atlas avatar Apr 05 '24 15:04 darius-atlas

I encountered this issue with a single jest.config file, which consumed a significant amount of my time. Following the suggestions provided here, I proceeded to delete the node_modules, nx/cache, and performed an nx reset, among other actions. However, upon reinstalling dependencies, I now encounter this error across all jest.config files. Frustrating, to say the least. :/

sagi-passion avatar Apr 08 '24 21:04 sagi-passion

This helped!

// displayName: 'whatever_project'

https://github.com/nrwl/nx/issues/22591#issuecomment-2028701651

sagi-passion avatar Apr 08 '24 21:04 sagi-passion

Any updates here? Running into this same issue. I'm doing a react-native-expo/react-vite monorepo app for my company and this is a huge barrier to us fully adopting Nx right now.

Not sure if commenting out displayName as the comment above suggests will have any unintended consequences.

enaluz avatar Apr 19 '24 17:04 enaluz

This helped!

// displayName: 'whatever_project'

#22591 (comment)

This doesn't work for me, I commented out displayName, and deleted .nx/cache. and it still throws the same error. upgrading the global nx install did solve the issue though.

Evanion avatar Apr 19 '24 22:04 Evanion

It happened randomly for me but nx reset fixes it all the time

blaqueMani avatar Apr 20 '24 15:04 blaqueMani

Very annoying issue which still persists in nx. When it will be fixed ?

michsien104 avatar Apr 21 '24 04:04 michsien104

"Fix" for me is to add an empty line to the file and save it, run the nx command again, and then revert the file again. nx reset seems to mostly trigger the problem for me.

KrekkieD avatar Apr 30 '24 08:04 KrekkieD

hey all!

This issue should have been fixed in Nx 19.0.0. Please update to that version, and you should be good to go.

If you still get this error after the update, please leave us a message and we'll take a look.

leosvelperez avatar May 13 '24 13:05 leosvelperez

Thanks for fixing it. @leosvelperez

randiguarcas avatar Jun 07 '24 02:06 randiguarcas

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.

github-actions[bot] avatar Jul 08 '24 00:07 github-actions[bot]