NextJS dev server does not reflect latest changes - javascript

While using npm run dev on a NextJS(v13) project, I am unable to see the latest changes I made in the code on browser. This is the first time I have faced such a issue and that also at 2 different times:
Redirects in next.config.js
async redirects() {
return [
{
source: '/',
destination: '/dashboard',
permanent: true
}
]
},
The destination was /overview prior to this and when I changed it to /dashboard I was still getting redirected to /overview. I got frustrated and left it there but when I started it the next day, the redirect was working fine!!
Usage of window on browser-side routes
Using window was giving an 'window undefined' error so I removed it from the project but that error still popped up. I tried a global search and there was no other mention of window object, which led me to this conclusion.
Possible issues:
I think the nextJS dev or build might be getting cached somewhere, I just dont know where.
I am using NextJS v13 and am using app/ directory which is yet experimental so that might be causing issues. (less likely)
Here is my directory structure(there are no server-side components):
What did I try?
Deleted .next folder thinking the build/dev code might be cached there (didnt work)
Restarted VSCode
Restarted PC
Could you guys give any suggestions on what might be causing this issue?

Related

I got 404 after page refresh inside routes on React + Vite app after deployed

So the problem is simple. After deploying my project to Railway i got 404 page after refresh inside my application. If i refreshing on home page everything ok, but after i do it inside the app (like /about) my app return 404 page.
The essence of the problem is that the server has no idea about the routes because all routing is only on client side.
I already research this problem, like cheking some other questions on stack overflow and googling it
This one on the internet
And this one on the stack overflow
Inside upper links there is some solutions, оne solution involves using Webpack and tweaking its configuration file a bit.
Something like that
devServer: {
historyApiFallback: true,
contentBase: './',
hot: true
},
But there is a problem, since i use Vite, i didn't find information about how to configure Vite to works that way.
I read Vite docs and maybe this is it, but I'm not sure if this is the solution to my problem.
Is it even possible to solve this problem using Vite, or do I need to completely migrate my app to Webpack?
Maybe I'm wrong and it's not even Vite's problem, but Railway's.
So, I am confused, if you have faced this problem and have a solution, please help
Not sure if you're using vite as the actual server (I don't think it's recommended), but have you tried adding appType to your vite.config.js? It worked well for me locally.
export default defineConfig({
plugins: [vue()],
appType: 'spa'
})
I didn't really find it in the docs anywhere but digging into the typefiles this looks like it might work.
I also found that adding --debug to see what happened with the routing when running locally was really helpful.

crbug/1173575, non-JS module files deprecated. (anonymous) # (index):6773 Woocommerce [duplicate]

I just created a new project and have run it for the first time using F5 or Ctrl + F5. The result in Chrome is:
The site can't be reached
err_connection_refused
I checked the option at the breakpoints for "Exceptions caught" and the following error is displayed.
Without "Exceptions caught" checked, the next error raised:
I tried to run "ng s -o" from the terminal and all work fine. The site is working well on port 4200, but I like to debug.
Here is my launch.json file, all by default:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "pwa-chrome",
"request": "launch",
"name": "Launch Chrome against localhost",
"url": "http://localhost:4200",
"webRoot": "${workspaceFolder}"
}
]
}
Why is this happening?
I also had this issue and none of the solutions listed were helpful.
However, the problem was rather easy to solve.
Just go into the Network tab of the Chrome Developer Console. Be sure that the connection is on No throttling and not Offline.
This misleading error message seemingly has nothing to do with Chrome or any deprecated functionality. It can have many root causes and seems to occur whenever connectivity can't be established.
I got this while following the React tutorial for Visual Studio Code. In that tutorial you start by creating a template with npx and then running it with npm start. That worked, and I could see that it was using http://localhost:3000 for the URL in the browser.
However, when I changed the code as the tutorial requested and set a breakpoint to debug, I got the error in the OP's post, both with Chrome and with Edge.
Visual Studio Code was creating a default launch.json file for debugging and populating it like this:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
"version": "0.2.0",
"configurations": [
{
"type": "pwa-chrome",
"request": "launch",
"name": "Launch Chrome against localhost",
"url": "http://localhost:8080",
"webRoot": "${workspaceFolder}"
}
]
}
And I needed to manually change the 8080 to 3000 which fixed the problem.
The key for me was configuring the breakpoint to catch the exception like the OP described (note - you can only configure that with the Debug icon selected in the far left icon menu). While the emitted error message is still the misleading "deprecated" one, there was a message that "the site can't be reached" which you can find if you dig a little - as shown here:
I imagine that practically any configuration issue that causes the connection to fail will cause this error. So firewall issues, missing host program, bad configuration (like mine), etc.
I had the same issue and the problem was with the URL. It was https://localhost:8000; in place of http://localhost:8000.
So try checking your URL and routes.
My server was just not running locally. :) Starting localhost solved it.
For me, the issue was a React/Next.js application was not running.
Basically, you have to keep the application running in a separate window/terminal to be able to attach the debugger. This is unlike the other application where it starts from debug console itself.
In my case, it got resolved by closing the browser and recompiling the app.
Instead of launching your application using the option "Launch Chrome against localhost", rather set your application name for launching - Resolved.
See the attached image for more context.
I had this same error and I resolved it by turning off my plugins. Specifically a CORS plugin I have been using.
Try this:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"request": "launch",
"name": "Launch Chrome against localhost",
"type": "dart"
}
]
}
I've tried many of the solutions suggested, and found someplace else this tip that was helpful:
I was unable to reach http://localhost:3000 from npm start run in a react app. So I tried: http://127.0.0.1:3000 and to my surprise it worked!
After some googling, I tried a suggestion to erase my browser cache, so I did it. All cached images and files (Google Chrome) and boom! It worked once again.
I have seen a lot of solutions for this problem, but nothing worked.
After a little debugging and commenting out many parts of the code, I managed to locate the issue.
Basically, it occurs on the backend; not the frontend.
There was an infinite loop that kept responses stuck. Fixing that issue, solved it for me.
I think we should just remove the cookies in that URL:
I displayed a similar message in my debug console and the problem was that the local web server was turned off and therefore unreachable.
I turned on the server in the virtual machine and the app started working again :-)
In my case, I had a Blazor solution and began receiving the "Crbug/1173575, non-JS module files deprecated message". Besides this, I also received a 404 error for the Index.html file!
The cause was that I inadvertently removed the reference in the .Server project to the .Client project. The project compiled fine without the reference, but I guess ASP.NET Core does some sort of reflection-based analysis on the dependencies to dynamically build the route map.
Restoring the reference to the .Client project on the .Server project fixed the problem.
In my case, the problem was because port 4200 was taken by another application (Docker). As soon as I changed the port to 4201 by adding the next structure in the serve section of angular.json file the problem was solved.
"options": {
"port": 4201
}
This may be of use to someone working on a project that communicates across iframes, I found this warning within a current web application: Crbug/1173575, non-JS module files deprecated.
In my case, the reason was that the resource iframe origin wasn't being served meaning the Iframe request URL was not accessible. When serving the resource the warning disappeared.
I had the error crbug/1173575, non-JS module files deprecated with some PDF files displayed in an iframe.
It was because they had a comma (",") in the filename. After renaming the file, everything was OK.
My problem was in the network settings of my Windows 10 computer, not on the browser. I have tried my URL in another computer and mobile browsers, and it was working fine.
So, I have fixed the issue by resetting my network settings
To do that, go to Settings → Network and Internet → Scroll down to Network reset.
Wait for 5 minute until it restarts.
I faced this issue while debugging in Visual Studio Code for an Angular application.
The probable causes may be the server is not up and listening to port. You may start the server manually by ng serve --port with port number. Also compare the URL in launch.json and compare the port number.
In my case it was caused by uBlock Origin. Disabling it on the website promptly fixed the error.
I was adding links to Amazon Affiliate while all of a sudden I faced this error.
To solve it, just stop your adblocker.
To add another angle to this. I named my JavaScript modules with .mjs. After setting my web server to serve mjs with MIME type application/javascript. I got the error
'crbug/1173575, non-JS module files deprecated.'
None of the answers here helped. To fix it I gave a path to the module.
From
<script type="module" src="xxx.mjs"></script>
To
<script type="module" src="./xxx.mjs"></script>
And the error went away.
I ran into this error on three separate Next.js projects. It was the same error in Chrome, Chrome Incognito, Firefox, and Edge.
It happened on a production build (next build && next start) and development server (next dev). After trying a number of fixes – ensuring I was on HTTP, not HTTPS, checking if the port was in use, deleting folder node_modules and running npm install, etc. – the thing that finally worked was restarting my computer...
For aiohttp.
I've stumbled upon this issue with an aiohttp server.
By default it was running on 0.0.0.0:8000 The solution was to change the host and the port to localhost:8080 in main.py file:
web.run_app(app, host='localhost', port=8080)
I had a similar issue. However, I discovered a different solution. It's still worth checking the steps in the GitHub link from the OP’s solution.
The project I was working on was made in an older version, and the launch.json URL had // delimiters. Replacing these with no delimiters resolved the issue.
from
"url":"file:///C://exampleParent//exampleChild//file.txt"
to
"url":"file:///c:/exampleParent/exampleChild/file.txt"
When I try and follow the steps described on Chrome Debugging with Angular CLI, I get a message that the library is no longer supported and a link to this article:
Request’s Past, Present and Future #3142
I had encountered the same problem in Visual Studio Code when I tried to debug a Python file. I resolved it by deleting the previous launch.json file and create a new one for this file.
I had a similar encounter in a JavaScript project. But I hadn’t learned JSON, but I just deleted the last three commands in
the JSON file that is removed the names "url" and "webroot".
I had the same issue with an app that needed to run navigator.geolocation.getCurrentPosition in my React application which of course needs HTTPS.
// .env.local HTTPS is set to true
HTTPS=true
The problem - I was loading the page with HTTP and not HTTPS.
Error Screenshot
Checking point (if you are working with a folder/file)
Check the folder/file name
Remove special characters (the folder/file name does not allow special characters)
Debug you code carefully (Java catch exception can't catch those errors)

react-dom installed, but not found. `Could not find module in path: 'react-dom/client' relative to`

Here is the Codesandbox
I want to run a rest, but the Tests tab shows this error.
Could not find module in path: 'react-dom/client' relative to
'/node_modules/#testing-library/react/dist/#testing-library/react.esm.js'
I referred to these but they did NOT solve my problem.
Reinstalling it in the devDependencies https://github.com/codesandbox/codesandbox-client/issues/2276
Turning off my UBlock origin. https://github.com/enzymejs/enzyme/issues/529
Trying different browsers
What should I do to successfully run this test?
This is a known issue.
The answer says you need to use a Terminal to run this. Terminal is just below the preview window.
https://github.com/codesandbox/codesandbox-client/issues/6599
Hey #eps1lon - Thank you for flagging this, the tests unfortunately don't work within Server sandboxes and we'll be removing them soon.
To run the tests you'll need to use the terminal. Sorry for the trouble!

React - Browser doesn't detect changes and console says '[HMR] Waiting for update signal from WDS...'

I am pretty new to React, sorry if I am asking something stupid. Any help would be highly appreciated :)
ENVIRONMENT
Ubuntu 20.04 in Windows 10 (WSL2)
Node version - v14.1.0
Npm version - v6.14.7
Code editor - VS Code v1.14.0
STEPS I DID
npx create-react-app <app-name>
cd <app-name>
npm start
https://localhost:3000 opens up in browser with default React landing page. Console says '[HMR] Waiting for update signal from WDS...
'
Delete all files in src directory and create empty index.js in src directory.
Output expected: Blank screen
Output: Default landing page of React even if I reload the page.
Struggles I made before asking this question :(
Looked in issues of create-react-app.
Tried troubleshooting create-react-app as mentioned in official docs.
Looked in stackoverflow for similar questions. Found some but none worked, maybe because my dev environment was different from them (WSL2 in Windows 10).
That sounds like a caching issue to me. My guess would be to clear your google chrome cache and try again. If that doesn't work, check your package.json file and make sure that under "scripts": "start" it says "react-scripts start".
Yayy! The issue is resolved.
It was my mistake :(.
All these days, I was trying to access the Windows filesystem from WSL2 and it seemed to be very slow. So I decided to work in the Linux filesystem itself. And everything works fine now. Thanks for helping :)

ERROR in Entry module not found: Error: Can't resolve '/usr/src/app/src/index.html' in '/usr/src/app'

Code that I wrote, works on my Mac and it did work on the Ubuntu server, but doesn't work anymore. It's my first time setting this stuff up, so I don't really understand the problem
I've tried editing Docker-compose.yml and webpack.development.js, but errors stay the same.Even if I change every path to different, error doesn't change
code from docker-compose.yml that is responsible for frontend
services:
frontend:
build: frontend
volumes:
- ./frontend/src:/usr/src/app/src
ports:
- 8000:8000
Rest of the code can be found in here, as I don't know, what you need for finding the problem
I expected it to act nicely and build the website, but it always gives the error:
ERROR in Entry module not found: Error: Can't resolve '/usr/src/app/src/index.html' in '/usr/src/app'.
It works perfectly fine on my Mac, and it worked two weeks ago on the server, but now it has broken after I added on the code. Even the original code won't work anymore
I thank everyone who even looks in the problem and apologize for the time lost on this

Categories

Resources