If you work with Next.js on Windows and have your repository inside OneDrive, sooner or later you may cross paths with this classic: EINVAL: invalid argument, readlink when trying to start npm run dev.
It happened to me, and I solved it with a very simple approach: identify the real cause (locks + strange links/symlinks in .next), clean safely, and then prevent it to stop wasting time.
## What's actually happening
When OneDrive is synchronizing a project folder, it can:
-
- lock files while Next is compiling
-
- “touch” file/folder metadata
-
- and, in some cases, leave inconsistent artifacts inside
.next(which is a volatile and high-turnover directory).
- and, in some cases, leave inconsistent artifacts inside
Result: Next tries to perform a readlink (read a symbolic link/junction) and Windows returns EINVAL.
## My review of the plan (what's right and what I would add)
Your base plan is correct and minimalist:
- Kill Node processes to release locks.
- Delete
.next(corrupted artifacts). - Delete
tsconfig.tsbuildinfoto force a clean recompilation. - Verify that the dev server reaches “Ready” and compiles routes.
What I add to make it “future-proof”:
-
- Prevent OneDrive from synchronizing
.next(ideal) or directly move the repo out of OneDrive.
- Prevent OneDrive from synchronizing
-
- If you need OneDrive due to company policy: at least exclude the project folder or use a non-synchronized local location and sync only docs/exports.
-
- If the team is large: leave a runbook (steps + commands + success criteria) for anyone to execute.
## Exact steps I use to fix it
Goal: return to a deterministic state before running
dev.
### 1) Terminate processes that block files
On Windows, the practical thing is to close terminals and kill active node.exe processes.
### 2) Safe cleaning of artifacts
I delete:
-
.next/
-
tsconfig.tsbuildinfo(if it exists)
### 3) Start dev and confirm “Ready”
My success criterion is not “it started”, it's seeing the log with:
-
✓ Starting...
-
✓ Ready in Xs
-
- and that it starts compiling routes without falling back into EINVAL.
## Verification evidence (what I expect to see)
A typical example of a “healthy state” looks like this:
```text
▲ Next.js 15.1.0
-
- Local: http://localhost:3000
✓ Starting...
✓ Ready in 7.4s
○ Compiling /src/middleware ... ✓ Compiled /src/middleware ... ○ Compiling /[locale]/contenidos ...
```
With that, for me, the error is resolved.
## How I prevent it from happening again
If you want my direct, no-nonsense recommendation:
-
- Don't have the repo inside OneDrive (best option).
-
- If you can't avoid it:
-
- Exclude .next from synchronization (if your OneDrive/IT allows it)
-
- or work in a non-synchronized local folder and push changes via Git as they should be.
.next is not “source code”, it's useful trash: if OneDrive interferes with it, it breaks your development cycle.
## If you want, I can make it bulletproof with you
When this type of error appears once, it's usually the tip of the iceberg: long paths, watchers, permissions, corrupted cache, CI different from local, etc.
If you want me to leave it stable (local + CI) and with a reproducible checklist, ask for a diagnosis with me.









