Skip to content
FR
  1. LuzineDebug
  2. JavaScript & Node.js

JavaScript & Node.js errors: causes and fixes

The most common JavaScript errors in the browser and in Node.js: TypeError, CORS, invalid JSON, missing modules, npm conflicts. Each page explains the message, its causes and a step-by-step fix.

TypeError: Cannot read properties of undefined (reading 'map')

Fix "Cannot read properties of undefined" in JavaScript

You are reading a property (here map) on a value that is undefined or null. The object before the dot does not exist yet or does n…

Beginner 10 min
Access to fetch at 'https://api.example.com/users' from origin 'http://localhost:5173' has…

Fix "blocked by CORS policy: No 'Access-Control-Allow-Origin' header"

The browser blocks the response because the API server did not allow your page’s origin. The fix is on the server: send the Access…

Intermediate 20 min
SyntaxError: Unexpected token '<', "<!DOCTYPE "... is not valid JSON

Fix "Unexpected token '<', "<!DOCTYPE "... is not valid JSON"

Your code calls response.json() or JSON.parse(), but the server returned an HTML page (starting with <!DOCTYPE) instead of JSON. I…

Beginner 10 min
Error: Cannot find module 'express'

Fix "Error: Cannot find module" in Node.js

Node.js cannot find the imported package or file. For a package ('express'), install it with npm install in the folder that contai…

Beginner 10 min
npm ERR! ERESOLVE unable to resolve dependency tree

Fix "npm ERR! ERESOLVE unable to resolve dependency tree"

npm refuses to install because two packages require incompatible versions of the same dependency, most often a peer dependency (Re…

Intermediate 15 min
Error: Hydration failed because the server rendered HTML didn't match the client. As a res…

Fix "Hydration failed because the server rendered HTML didn’t match the client" (React, Next.js)

The HTML generated on the server and React’s first render in the browser are not identical. Most often, a component renders a brow…

Intermediate 20 min
Error: Too many re-renders. React limits the number of renders to prevent an infinite loop…

Fix "Too many re-renders. React limits the number of renders" in React

A component updates its state during its own render, which triggers a new render, which updates the state, and so on. The most com…

Beginner 10 min
Error: listen EADDRINUSE: address already in use :::3000

Fix "Error: listen EADDRINUSE: address already in use" in Node.js

The port your Node.js server wants to listen on (here 3000) is already taken, most often by an old instance of your own server tha…

Beginner 5 min
SyntaxError: Cannot use import statement outside a module

Fix "SyntaxError: Cannot use import statement outside a module"

A file uses the ES modules import syntax while it is loaded as a classic script or as CommonJS. In Node.js, add "type": "module" t…

Intermediate 15 min

Other areas