You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
TypeError [ERR_INVALID_CHAR]: Invalid character in header content ["X-React-Native-Project-Root"] at ServerResponse.setHeader (node:_http_outgoing:651:3) #2279
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)
I had the same issue. And I was researching a lot and I found this^
Go to node_modules/@react-native-community/cli-server-api/build/statusPageMiddleware.js
On line 19 wrap process.cwd() to new URL() like this: new URL(process.cwd())
Before reload clean cache in npm using npm cache clean --force
Run using npm run start / npm run android
I hope this will help you too 😇
Reacted by Vitalii Yechkalov, Renyrsss, Daiki11101, Essonti, İlayda Mülazimoğlu, Martin Zdravkov, Orzibek, Vahan Ghazaryan, Maksim Zelenskiy, Vergo and 15 more
Reacted by Boughazi Akram, Hrvoje Šuta, SeanHo, Le Thien, Asker, Yevhenii Danoi, Tarek Siddique Nabil, Stoyan Bochukov, Seyitmammedov Davut, pncuong03 and 44 more
I had the same issue. And I was researching a lot and I found this^
Go to node_modules/@react-native-community/cli-server-api/build/statusPageMiddleware.js
On line 19 wrap process.cwd() to new URL() like this: new URL(process.cwd())
Before reload clean cache in npm using npm cache clean --force
Run using npm run start / npm run android
I hope this will help you too 😇
thank you saved my dev day 😊
Reacted by Rafik, Hrvoje Šuta, Seyitmammedov Davut, ciewax, Yaroslava-Vorobets, Ruslan Rahmatov, Vitalii Yechkalov, Maksim Zelenskiy and AlejandroRamos781
I had the same issue. And I was researching a lot and I found this^
Go to node_modules/@react-native-community/cli-server-api/build/statusPageMiddleware.js
On line 19 wrap process.cwd() to new URL() like this: new URL(process.cwd())
Before reload clean cache in npm using npm cache clean --force
Run using npm run start / npm run android
I hope this will help you too 😇
I got
TypeError: Invalid URL
at new URL (node:internal/url:775:36)
at statusPageMiddleware (/node_modules/@react-native-community/cli-server-api/build/statusPageMiddleware.js:20:48)
``
Reacted by whitebrand, Boughazi Akram, Italo Lima, Shahzod Uktamov, Yaroslava-Vorobets, Abdelrahman Abounida, NewDimix, Diego Alejandro Cifuentes, couqiao and Dasen Yan
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.
Reacted by Boughazi Akram, chinieer, Paulo Cardoso, Lucía, Gustavo Ramos, Malek Boubakri, wawahuhu, ChenBr, Andrew Enrique Oliveira and Ahmet Eren Odacı
Reacted by Abdelrahman Abounida, Eduardo Carneiro, ChenBr and Essonti
ATUALIZAÇÃO: Se alguém tiver o mesmo erro, por favor, verifique o caminho da pasta do seu projeto e confirme se não há caracteres especiais nela. No exemplo desta edição o caminho possui caracteres árabes C:\Users\kikou\OneDrive\المستندات\ReactNative projects\, o mesmo para acentos "áéíóú", "àèìòù" ou qualquer outro caractere "çñ..." não inglês. Verifique o caminho completo e tente criar o aplicativo novamente.
Sorted out. My path had space between two texts. Space removed and the problem went away.
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"
Reacted by binaryify, Myeong Su Chae, Aline Hy, kunkun-s, DANG XUAN NAM, Fernando Castro, nullaugh, AtulCube, Ziyan Liu and shawn sxw
Reacted by binaryify, DANG XUAN NAM, nullaugh and Ziyan Liu
Reacted by binaryify, DANG XUAN NAM, nullaugh, Ziyan Liu and Ibraheem Qadi
Reacted by Boughazi Akram, Diakonov Andrey, Paweł Gacek, Arnaud Ambroselli, Nguyễn Thái Học, binaryify, vare4ka, DANG XUAN NAM, nullaugh and Ziyan Liu
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"
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.
TypeError [ERR_INVALID_URL]: Invalid URL
at new NodeError (node:internal/errors:400:5)
at URL.onParseError (node:internal/url:565:9)
at new URL (node:internal/url:645:5)
at statusPageMiddleware (/Users/zhangwencai/qianduan/code/AwesomeProject/node_modules/@react-native-community/cli-server-api/build/statusPageMiddleware.js:19:48)
at call (/Users/zhangwencai/qianduan/code/AwesomeProject/node_modules/connect/index.js:239:7)
at next (/Users/zhangwencai/qianduan/code/AwesomeProject/node_modules/connect/index.js:183:5)
at next (/Users/zhangwencai/qianduan/code/AwesomeProject/node_modules/connect/index.js:161:14)
at next (/Users/zhangwencai/qianduan/code/AwesomeProject/node_modules/connect/index.js:161:14)
at next (/Users/zhangwencai/qianduan/code/AwesomeProject/node_modules/connect/index.js:161:14)
at next (/Users/zhangwencai/qianduan/code/AwesomeProject/node_modules/connect/index.js:161:14)
TypeError [ERR_INVALID_URL]: Invalid URL
at new NodeError (node:internal/errors:400:5)
at URL.onParseError (node:internal/url:565:9)
at new URL (node:internal/url:645:5)
at statusPageMiddleware (/Users/zhangwencai/qianduan/code/AwesomeProject/node_modules/@react-native-community/cli-server-api/build/statusPageMiddleware.js:19:48)
at call (/Users/zhangwencai/qianduan/code/AwesomeProject/node_modules/connect/index.js:239:7)
at next (/Users/zhangwencai/qianduan/code/AwesomeProject/node_modules/connect/index.js:183:5)
at next (/Users/zhangwencai/qianduan/code/AwesomeProject/node_modules/connect/index.js:161:14)
at next (/Users/zhangwencai/qianduan/code/AwesomeProject/node_modules/connect/index.js:161:14)
at next (/Users/zhangwencai/qianduan/code/AwesomeProject/node_modules/connect/index.js:161:14)
at next (/Users/zhangwencai/qianduan/code/AwesomeProject/node_modules/connect/index.js:161:14)
You can try to move project to another path or try the second way described in my answer higher
hey! is anyone able to validate if this fix is working properly? We'd like to upstream this change :)
diff --git forkSrcPrefix/packages/cli-server-api/src/statusPageMiddleware.ts forkDstPrefix/packages/cli-server-api/src/statusPageMiddleware.ts
index 3e98f2b2b46c6401bb3630c746787aec1b8dac3c..2417950d2bf0b88398d2441c6f8484cacddf8900 100644
--- forkSrcPrefix/packages/cli-server-api/src/statusPageMiddleware.ts+++ forkDstPrefix/packages/cli-server-api/src/statusPageMiddleware.ts@@ -5,6 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/
import http from 'http';
+import path from 'path';
/**
* Status page so that anyone who needs to can verify that the packager is
@@ -14,6 +15,7 @@ export default function statusPageMiddleware(
_req: http.IncomingMessage,
res: http.ServerResponse,
) {
- res.setHeader('X-React-Native-Project-Root', process.cwd());+ const projectRoot = path.normalize(process.cwd());+ res.setHeader('X-React-Native-Project-Root', projectRoot);
res.end('packager-status:running');
}
hey! is anyone able to validate if this fix is working properly? We'd like to upstream this change :)
diff --git forkSrcPrefix/packages/cli-server-api/src/statusPageMiddleware.ts forkDstPrefix/packages/cli-server-api/src/statusPageMiddleware.ts
index 3e98f2b2b46c6401bb3630c746787aec1b8dac3c..2417950d2bf0b88398d2441c6f8484cacddf8900 100644
--- forkSrcPrefix/packages/cli-server-api/src/statusPageMiddleware.ts+++ forkDstPrefix/packages/cli-server-api/src/statusPageMiddleware.ts@@ -5,6 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/
import http from 'http';
+import path from 'path';
/**
* Status page so that anyone who needs to can verify that the packager is
@@ -14,6 +15,7 @@ export default function statusPageMiddleware(
_req: http.IncomingMessage,
res: http.ServerResponse,
) {
- res.setHeader('X-React-Native-Project-Root', process.cwd());+ const projectRoot = path.normalize(process.cwd());+ res.setHeader('X-React-Native-Project-Root', projectRoot);
res.end('packager-status:running');
}
I started the project, but this solution does not work and should not work in theory. The problem is not slashes in the path to the project, but that there may be characters in the path that require conversion via a new URL (you can see the problem in detail in my comment on this problem above). The solution I described works for me
Activity
RafikGadzhiyev commentedon Jan 26, 2024
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.jsnew URL(process.cwd())npm using npm cache clean --forcenpm run start/npm run androidI hope this will help you too 😇
bouakram commentedon Jan 26, 2024
thank you saved my dev day 😊
bouakram commentedon Jan 26, 2024
the solution provided by @RafikGadzhiyev is correct thanks to him.
arnaudambro commentedon Jan 28, 2024
I got
whitebrand commentedon Jan 30, 2024
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.ThienLE0811 commentedon Feb 2, 2024
Thank you, my problem has been solved
pauloscardoso commentedon Feb 8, 2024
Sorted out. My path had space between two texts. Space removed and the problem went away.
Andrey123815 commentedon Feb 17, 2024
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"
bruno-keiko commentedon Feb 29, 2024
Thank you, this worked for me.
GustavoHNRamos commentedon Mar 18, 2024
Thank you, my path had a non english character
hw514352 commentedon Apr 7, 2024
deleting the 19 line X-React-Native-Project-Root
wencai123 commentedon Apr 23, 2024
My path looks fine, but I still get an error
TypeError [ERR_INVALID_URL]: Invalid URL
at new NodeError (node:internal/errors:400:5)
at URL.onParseError (node:internal/url:565:9)
at new URL (node:internal/url:645:5)
at statusPageMiddleware (/Users/zhangwencai/qianduan/code/AwesomeProject/node_modules/@react-native-community/cli-server-api/build/statusPageMiddleware.js:19:48)
at call (/Users/zhangwencai/qianduan/code/AwesomeProject/node_modules/connect/index.js:239:7)
at next (/Users/zhangwencai/qianduan/code/AwesomeProject/node_modules/connect/index.js:183:5)
at next (/Users/zhangwencai/qianduan/code/AwesomeProject/node_modules/connect/index.js:161:14)
at next (/Users/zhangwencai/qianduan/code/AwesomeProject/node_modules/connect/index.js:161:14)
at next (/Users/zhangwencai/qianduan/code/AwesomeProject/node_modules/connect/index.js:161:14)
at next (/Users/zhangwencai/qianduan/code/AwesomeProject/node_modules/connect/index.js:161:14)
Andrey123815 commentedon Apr 23, 2024
You can try to move project to another path or try the second way described in my answer higher
wencai123 commentedon Apr 24, 2024
Problem solved, thank you
itlingxiu commentedon Apr 30, 2024
@hw514352 这个方法挺管用的
itlingxiu commentedon Apr 30, 2024
szymonrybczak commentedon Jul 9, 2024
hey! is anyone able to validate if this fix is working properly? We'd like to upstream this change :)
Andrey123815 commentedon Jul 11, 2024
I started the project, but this solution does not work and should not work in theory. The problem is not slashes in the path to the project, but that there may be characters in the path that require conversion via a new URL (you can see the problem in detail in my comment on this problem above). The solution I described works for me
aligururyaman commentedon Jul 22, 2024
Thanks....
muhammetfeyzi commentedon Aug 7, 2024
If it doesn't work after all this, reload it and the emulator will work for me :)
Kamo72 commentedon Oct 24, 2024
thx for giving me solution! it works :D
Mehmetulas98 commentedon May 1, 2025
You have to be carefull for project folder names. Turkish characters, commas and blanks are not valid.