cli: TypeError [ERR_INVALID_CHAR]: Invalid character in header content ["X-React-Native-Project-Root"] at ServerResponse.setHeader (node:_http_outgoing:651:3)
Description
I encountered the following error when starting a new React Native project:
Steps to Reproduce:
Create a new React Native project using the React Native CLI. Run the project using the command: npm start -> a for android. Observe the error mentioned above.
Expected Behavior
I expected the new React Native project to start without any errors.
Error
info Opening app on Android… TypeError [ERR_INVALID_CHAR]: Invalid character in header content [“X-React-Native-Project-Root”] at ServerResponse.setHeader (node:_http_outgoing:651:3)
Environment
Node.js version: >=18 npm version: 10.1.0
React Native Version 0.73.2
Affected Platforms Runtime - Android, Build - Windows
Output of npx react-native info
info Fetching system and libraries information... ... System: OS: Windows 11 10.0.22621 CPU: (8) x64 Intel(R) Core(TM) i5-10310U CPU @ 1.70GHz Memory: 2.37 GB / 15.77 GB Binaries: Node: version: 18.17.0 path: C:\Program Files\nodejs\node.EXE Yarn: Not Found npm: version: 10.1.0 path: C:\Program Files\nodejs\npm.CMD Watchman: Not Found SDKs: Android SDK: Not Found Windows SDK: Not Found IDEs: Android Studio: AI-223.8836.35.2231.10406996 Visual Studio: Not Found Languages: Java: 11.0.20 Ruby: Not Found npmPackages: "@react-native-community/cli": Not Found react: installed: 18.2.0 wanted: 18.2.0 react-native: installed: 0.73.2 wanted: 0.73.2 react-native-windows: Not Found npmGlobalPackages: "*react-native*": Not Found Android: hermesEnabled: true newArchEnabled: false iOS: hermesEnabled: Not found newArchEnabled: Not found ...
Stacktrace or Logs
info Opening app on Android... TypeError [ERR_INVALID_CHAR]: Invalid character in header content ["X-React-Native-Project-Root"] at ServerResponse.setHeader (node:_http_outgoing:651:3) at statusPageMiddleware (C:\Users\kikou\OneDrive\المستندات\ReactNative projects\algbnb\client\node_modules\@react-native-community\cli-server-api\build\statusPageMiddleware.js:19:7) at call (C:\Users\kikou\OneDrive\المستندات\ReactNative projects\algbnb\client\node_modules\connect\index.js:239:7) at next (C:\Users\kikou\OneDrive\المستندات\ReactNative projects\algbnb\client\node_modules\connect\index.js:183:5) at next (C:\Users\kikou\OneDrive\المستندات\ReactNative projects\algbnb\client\node_modules\connect\index.js:161:14) at next (C:\Users\kikou\OneDrive\المستندات\ReactNative projects\algbnb\client\node_modules\connect\index.js:161:14) at next (C:\Users\kikou\OneDrive\المستندات\ReactNative projects\algbnb\client\node_modules\connect\index.js:161:14) at next (C:\Users\kikou\OneDrive\المستندات\ReactNative projects\algbnb\client\node_modules\connect\index.js:161:14) at nocache (C:\Users\kikou\OneDrive\المستندات\ReactNative projects\algbnb\client\node_modules\nocache\index.js:11:5) at call (C:\Users\kikou\OneDrive\المستندات\ReactNative projects\algbnb\client\node_modules\connect\index.js:239:7)
Screenshots and Videos
About this issue
- Original URL
- State: closed
- Created 5 months ago
- Comments: 16
Commits related to this issue
- Fixed problem by using https://github.com/react-native-community/cli/issues/2279 — committed to AndrewWladis/taylor-game by AndrewWladis 2 months ago
I had the same issue. And I was researching a lot and I found this^
node_modules/@react-native-community/cli-server-api/build/statusPageMiddleware.js
new URL(process.cwd())
npm using npm cache clean --force
npm run start
/npm run android
I hope this will help you too 😇
Same here, did you solve it @arnaudambro ?
UPDATE: If anyone else has the same error, please, check your project folder path and confirm there aren´t any special characteres on it. In the example of this issue the path has Arabic characters
C:\Users\kikou\OneDrive\المستندات\ReactNative projects\
, same for accents “áéíóú”, “àèìòù” or any other non english “çñ…” character. Check this for the full path and then try to build the app again.I got
thank you saved my dev day 😊
THE PROBLEM IS ONLY IN PATH TO YOUR PROJECT
You can use only latine chars, may also use “-” in naming
If your path to project naming is correct you dont need any ways written higher
But if you need path with not correct chars you may CHANGE IN FILE node_modules/@react-native-community/cli-server-api/build/statusPageMiddleware.js STRING res.setHeader(‘X-React-Native-Project-Root’, process.cwd()); TO res.setHeader(‘X-React-Native-Project-Root’, new URL(process.cwd(), ‘file://’));
and always will work (don’t forget to clear cache!)
newc URL allow us to make ref to local root file, for example: for path “/home/user/Рабочий стол” link pathname will be like “'/home/user/%D0%A0%D0%B0%D0%B1%D0%BE%D1%87%D0%B8%D0%B9%20%D1%81%D1%82%D0%BE%D0%BB”
Thank you, my path had a non english character
Thank you, this worked for me.
Sorted out. My path had space between two texts. Space removed and the problem went away.
Thank you, my problem has been solved
the solution provided by @RafikGadzhiyev is correct thanks to him.