Same repository, same commit, same package-lock.json: On one computer, the Angular app runs flawlessly, on another it dies immediately at bootstrap with an NG0203 error. In the end, neither Angular nor npm were at fault — it was a folder called rene.poepperl.000.
Tested with: Angular 22.0.8 · @angular/build 22.0.7 · Node 24 · Windows · Vite Dev Server
NG0203 error despite flawless source code
Since last Friday, this phenomenon has been driving me crazy. On my development machine, the Angular app booted without issues; on the development server in development mode (Windows Server with Remote Desktop), only a white screen appeared, and the browser console showed the following error message:
ERROR RuntimeError: NG0203: The `EnvironmentInjector` token injection failed.
`inject()` function must be called from an injection context…
at injectInjectorOnly (_pending_tasks-chunk.mjs:667:11)
at ɵɵinject (_pending_tasks-chunk.mjs:684:40)
at Object.factory (_debug_node-chunk.mjs:10034:42)
at R3Injector.hydrate (_pending_tasks-chunk.mjs:1314:11)
at __spreadProps.getStandaloneInjector (_debug_node-chunk.mjs:10054:31)
at createRootViewInjector (_debug_node-chunk.mjs:8994:44)
at ComponentFactory.create (_debug_node-chunk.mjs:9065:32)
What does error NG0203 normally mean?
This error occurs when you use Angular’s inject() function outside of a valid injection context. So it’s (essentially) about Angular’s Dependency Injection.
Valid injection contexts are:
- Class constructors
- Field initializers
- Factory functions: inside the factory function of an InjectionToken or when configuring providers with useFactory
- Functional router guards & resolvers (CanActivateFn or ResolveFn, etc.)
A look at main.ts, app.config.ts, and the various components, however, showed that everything was clean. Standard setup with provideRouter & co. Nothing suspicious.
If the same code works on computer A but not on computer B, the code is rarely the problem.
Step 1: First things first: Narrow down the search space
Before you spend hours reading code: The Angular dev server (Vite with on-the-fly modules) and the production build (esbuild with fixed bundles) work completely differently.
Run this command:
npx ng build --configuration development
npx http-server dist/DeinProjekt/browser
This command bypasses the built-in Angular Vite dev server, creates a build, and serves it with a simple http server. If that works, the issue is definitely not in the code or dependencies, but somewhere in the Vite dev server.
Step 2: Analyze the module graph
The error message NG0203 indicates that, contrary to expectations, there is no injection context at the point where inject is called, and this in turn can be caused by a multi-instance problem. If the dev server loads Angular Core multiple times instead of just once, the injection context is created during the first load, but inject is called in the second instance without an injection context. And then, it crashes.
So, troubleshooting should continue in the network tab of the browser dev tools to gain clarity here.
In my case, the dev server actually delivered the modules/module chunks with two different hashes. This means Angular Core was processed twice by the pre-bundler, and both versions were loaded into the Angular app:
| Angeforderte Datei | Typ | Größe |
|---|---|---|
main.js |
script | 104 kB |
@angular_platform-browser.js?v=abc4743f |
script | 50,2 kB |
@angular_core.js?v=abc4743f |
script | 998 kB |
@angular_router.js?v=abc4743f |
script | 261 kB |
| ... | ... | ... |
chunk-GMRBKFW6.js?v=7c52e23b |
script | 89,3 kB |
chunk-KXOBELG4.js?v=7c52e23b |
script | 905 kB |
Two different hashes (abc4743f and 7c52e23b) mean: Angular Core was pre-bundled and loaded twice (~998 KB + ~905 KB). One instance sets the injector, the other finds null—boom, NG0203.
Step 3: Identify the culprit
Once it was clear that two instances of Angular were actually loaded, the question was: Why?
A closer look at the Sources tab in the browser dev tools helped.
This showed that one instance was loaded from C:\Users\rene.poepperl\Documents\Projekt, and the other from C:\Users\rene.poepperl.000\Documents\Projekt. The culprit was therefore my Windows profile folder.
What happened here?
On Windows, a profile folder with the .000 suffix is created when Windows cannot load the original user profile during login. Then, Windows creates a new profile in the background and links old paths using so-called junctions (file system links, also called reparse points).
These junctions actually ultimately point to the same files. But: Node.js and Vite resolve paths via realpath() in some places and not in others, causing inconsistent path names. Vite thinks it is working with two different directories and bundles node_modules twice. Congratulations!
The solution: Clean workspace setup
The fix is simple, but requires a consistent move:
Move the project to a real, shallow path without reparse points (e.g.
C:\dev\YourProject).Important: Do not take the
node_modulesfolder with you! Otherwise, you will drag along the broken path references.Reinstall the dependencies
Afterwards, check in the dev server (network tab) if all Angular chunks have exactly the same ?v=... hash. If so, the app will run stable again.