Fresh ReactJS project stuck at starting the development server - reactjs

I am running a fresh react project with no single line of code written by me.
All I did was:
npx create-react-app my-app
npm install
npm start
The browser window opens and within my console window I see "Starting the development server". It is stuck there, have been keeping it up for over an hour with no progress.
I looked at different SO threads as well as many suggestions on other platforms. From limiting the RAM available to using another port, closing all browser windows, rebooting my machine - nothing helped.
Do you have any suggestions for troubleshooting?
Running on macOS 13.1 on M1 Pro.

It was the directory I started the project in. Using spaces and several special characters seems to break react as well es next.js which I tried next.

Related

installing npm package crashes react native application

I've set up a React Native application that works fine with an emulator till I try to install the moment library to work with dates. This library won't even finish to install and then commands are not recognized anymore.
At the begining, everything runs correctly :
Then, installing the moment library :
Since the installation runs for ages, I did a Ctrl+C on it. Then the Metro and Android command won't be recognized :
However, these commands are still in the package.json :
From that point, the app is completely messed up. I have to erase everything and start all over again.
So? is it that npm packages cannot be used like in a regular React app? I don't understand what is going on here.
Thank you for your help.

Hot reload stopped working after adjusting environment for work requirements

I started a new developer role a few days ago and made some environmental changes to adapt for work. Since then, my hot reload/fast refresh has just stopped working entirely. Changes don't show up even if I refresh the page manually. Only shows changes when I stop the dev server and restart it with 'npm run dev'. The triangle indicator at the bottom right should be active, showing active reload of the window (this no longer shows up consistently either, and if it does the page gets reloaded, but alas the proposed changes aren't visible)
Context:
It has this effect on all NextJS and react applications of mine. Even running a basic project template off the NextJS examples page shows no hot reload working.
I researched this issue and it seems wrong imports (e.g. importing components using lowercase or files in the pages directory being capitalized) can cause this, but I combed through the code and can't spot any issues (of course, I could be missing it but my codebase is over 300 files).
Service workers in the background can cause issues, but I cleared my browser of all of them to be sure and it still doesn't fix it.
I installed ngrok for tunneling for work purposes and docker-compose to handle the work dev. environment.
Made sure I'm using the latest Next version. Even deleted node_modules and ran npm install. Deleted .next and the out folder and still no luck.
Anybody have any ideas or clues to what I should try next? Is it related to the stuff I installed for work? Something related to VS code or WSL2? Seems so puzzling it kind of just happened overnight. Thanks for any insight or advice!
System information
OS: Windows (WSL2 virtualization for VS code)
Browser: Chrome
Version of Next.js: 10.0.3
Version of Node.js: 14.8.0
Deployment: npm run dev for development work; amplify publish for AWS hosting
The problem is with WSL2. I use WSL2 inside VS Code; which is a big performance upgrade in the Linux environment. The problem is WSL2 is actually in a 'virtualization' and thus cannot send information from VS Code AND the browser (localhost:3000) at the same time.
It's a big issue they are working on and there is no fix yet for it. That's why fast refresh doesn't work because localhost is not receiving the changes being made. Either proxy through or revert back to WSL1 https://github.com/microsoft/WSL/issues/4769
Solution provide by OP on question section
Add a .env file or a .env.local file to your root and put this line on it:
WATCHPACK_POLLING=true
Now, restart your server.
Thanks I encounter the same issue with WSL2. I just switch to windows terminal and it works.
If you run Poweshell as administrator and run
wsl.exe -l -v
This will give you th eversion of wsl your distros run on.
I am personally using Ubuntu, and this is the output
Ubuntu Running 2
docker-desktop Stopped 2
docker-desktop-data Stopped 2
To switch to wsl 1,
Run
wsl.exe --set-version Ubuntu 1
and if you wanna switch back,
run,
wsl.exe --set-version Ubuntu 2.
This worked for me.
In my react projects, I just add in my .env file at the root project folder the values
FAST_REFRESH=false
CHOKIDAR_USEPOLLING=true
and it works! enjoy!
The problem is with WSL2. I use WSL2 inside VS Code. But React JS and Next JS projects don't auto-reload. So, add a .env or .env.local (recommended) file to your root and put these lines on it:
WATCHPACK_POLLING=true
CHOKIDAR_USEPOLLING=true
Now, restart your server.

react scripts start - hot reload are too slow?

I am using create-react-app to create my react projects boilerplates but recently launching my projects with npm start is too slow and most recently hot reloading is slow take from 5 - 15 secs to rebuild the page after any change especially when rebuilding after an error.
I really don't know much about webpack, after some search i found that problem can be from webpack or webpack-dev-server but i don't know much about them
so i don't know from where should i move to solve this issue?
If you're developing a React project in a Windows Subsystem for Linux 2 (WSL2) environment, it's especially important that you work within the WSL2 directory structure for optimal I/O. For example, you'll want to put the project in "~/repos/my-project", not "/mnt/c/Users/my-username/repos/my-project". They aren't the same location. You can confirm this by running "explorer.exe ." from the terminal.

React Electron App built with asar on gitlab runner creates JavaScript errors

i will just start my question a little bit structured:
background information
I am developing a React App with Electron on my Mac.
The customer uses this app on Windows 7 and 10.
The app is packaged with asar on a gitlab runner within a docker
the dockerfile for the runner is from electronuserland/builder:base
What works?
If I start the App locally I run the npm build script and start electron -> The app works fine!
If I package the App locally (on my Mac) for Windows and copy the .exe to my VM: -> The app works fine!
What does not work?
If my pipeline get triggered by my commit the gitlab runner starts to run the buildscript and the package script (The same ones I run locally for packaging and running my app) The build is "successfully" completed and the artifacts are stored on gitlab.
Then I download the .exe from the gitlab artifacts on my Windows VM and install the software. This absolutely works fine. The app can start up and some functions are pretty good working.
But there is a problem with a package (or maybe some more, i do not know yet) It is the react-bootstrap-daterangepicker. It gives me an JS error with $this.$picker.daterangepicker is not a function
I googled a lot and found existing problems with the package, but I do not understand why it is working when i package the app locally and not with the runner.
I removed my node-modules completey on my local machine and reinstalled them, and it is still working fine.
Do you have any idea?
Where could be a difference between my local environment and the runner environment that can cause this kind of problem?
I am pretty stuck in this problem, and you would be my hero if you can help me to fix this!
Have a nice day!
electron-builder recommends using electronuserland/builder:wine to build Windows targets. I'm not sure if this would fix the problem, but could you try using this image instead?
electronuserland/builder:wine — Wine, NodeJS 10 and required system dependencies. Based on builder:10. Use this image if you need to build Windows targets.
For more information: https://www.electron.build/multi-platform-build#provided-docker-images

React Native Expo Timout Error

I'm currently trying to learn react native. I created a project using create-react-native-app. After the project is created, I started npm start on the folder which shows the QR code. I've installed the expo app on my android phone and scanned the code but I'm getting a Uncaught Error: Timed out, no manifest in cache on my expo app and there is no stack trace given.
I've made it work a while ago but somehow its currently not working.
Im using windows 10.
npm 5.6
yarn 1.5.1
What I've done to fix it using Ubuntu was (I created my app using create-react-native-app):
open terminal
execute ifconfig
find network interface (wlp4s0, in my case)
execute export REACT_NATIVE_PACKAGER_HOSTNAME="IP_FOUND_BEFORE"
yarn start
SUCCESS! Finished building JavaScript bundle in 10069ms
Expo only supports the most recent 6 versions, this is because we have to have all the native code for each version on the client and that gets big fast 🙃💣. As of writing this v26 is almost out, that version of the expo client will not support v19 projects. Please make sure that your app is up-to-date by going to the app.json (or exp.json depending on how old your project is 😅) and checking the version number.
Outside of that, I would also recommend you start your project by calling exp start in the root folder of your project 💙
The problem that causes this is having multiple network connections. In my case, I have a virtual network connection which is used by the packager instead of the wifi connection. So basically what's happening is that my phone and my computer uses different connections. I've found a solution here: https://github.com/react-community/create-react-native-app/issues/598

Resources