In Node.js v21+, TypeError [ERR_INVALID_ARG_VALUE] from util.styleText()
Description
The React Native development server fails to start on Node.js v21+ with the following error:
` TypeError [ERR_INVALID_ARG_VALUE]: The argument 'format' must be one of: 'reset', 'bold', 'dim', 'italic', 'underline', 'blink', 'inverse', 'hidden', 'strikethrough', 'doubleunderline', 'black', 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'white', 'bgBlack', 'bgRed', 'bgGreen', 'bgYellow', 'bgBlue', 'bgMagenta', 'bgCyan', 'bgWhite', 'framed', 'overlined', 'gray', 'redBright', 'greenBright', 'yellowBright', 'blueBright', 'magentaBright', 'cyanBright', 'whiteBright', 'bgGray', 'bgRedBright', 'bgGreenBright', 'bgYellowBright', 'bgBlueBright', 'bgMagentaBright', 'bgCyanBright', 'bgWhiteBright'. Received [ 'bold', 'inverse' ]
at styleText (node:util:210:5)
at attachKeyHandlers (/path/to/node_modules/@react-native/community-cli-plugin/dist/commands/start/attachKeyHandlers.js:91:25)
`
Steps to reproduce
- Steps to Reproduce
- Install Node.js v21.0.0 or higher
- Create a new React Native project or use existing one
- Run npx react-native start
- Observe the error
React Native Version
0.82.1
Affected Platforms
Other (please specify)
Output of npx @react-native-community/cli info
React Native version: 0.82.1
@react-native/community-cli-plugin version: 0.82.1
Node.js version: 21.7.3
Operating System: macOS 23.3.0
Stacktrace or Logs
`
TypeError [ERR_INVALID_ARG_VALUE]: The argument 'format' must be one of: 'reset', 'bold', 'dim', 'italic', 'underline', 'blink', 'inverse', 'hidden', 'strikethrough', 'doubleunderline', 'black', 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'white', 'bgBlack', 'bgRed', 'bgGreen', 'bgYellow', 'bgBlue', 'bgMagenta', 'bgCyan', 'bgWhite', 'framed', 'overlined', 'gray', 'redBright', 'greenBright', 'yellowBright', 'blueBright', 'magentaBright', 'cyanBright', 'whiteBright', 'bgGray', 'bgRedBright', 'bgGreenBright', 'bgYellowBright', 'bgBlueBright', 'bgMagentaBright', 'bgCyanBright', 'bgWhiteBright'. Received [ 'bold', 'inverse' ]
at styleText (node:util:210:5)
at attachKeyHandlers (/path/to/node_modules/@react-native/community-cli-plugin/dist/commands/start/attachKeyHandlers.js:91:25)
MANDATORY Reproducer
https://github.com/jiangtao/react-native-in-node21
Screenshots and Videos
No response
[!WARNING] Missing reproducer: We could not detect a reproducible example in your issue report. Reproducers are mandatory and we can accept only one of those as a valid reproducer:
- For majority of bugs: send us a Pull Request with the RNTesterPlayground.js edited to reproduce your bug.
- If your bug is UI related: a Snack
- If your bug is build/upgrade related: a project using our Reproducer Template
You can read more about about it on our website: How to report a bug.
Warning
Missing reproducer: We could not detect a reproducible example in your issue report. Reproducers are mandatory and we can accept only one of those as a valid reproducer:
- For majority of bugs: send us a Pull Request with the RNTesterPlayground.js edited to reproduce your bug.
- If your bug is UI related: a Snack
- If your bug is build/upgrade related: a project using our Reproducer Template
You can read more about about it on our website: How to report a bug.
add the Reproducer
To solve this problem, there are two solutions:
- Use at least Node.js version 22 or higher.
- Adapt
styleTextto Node.js version 21, ensuring compatibility with version 22 parameters.
If the solution is confirmed, I can fix it.
@mojodna
node_modules\@react-native\community-cli-plugin\dist\commands\start\attachKeyHandlers.js
lines 91...93:
${(0, _util.styleText)("bold", (0, _util.styleText)("inverse", " r "))} - reload app(s)
${(0, _util.styleText)("bold", (0, _util.styleText)("inverse", " d "))} - open Dev Menu
${(0, _util.styleText)("bold", (0, _util.styleText)("inverse", " j "))} - open DevTools