Skip to content

Error ng serve cannot read C: directory : Access is denied #29664

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
1 task done
guenounrub opened this issue Feb 19, 2025 · 4 comments
Open
1 task done

Error ng serve cannot read C: directory : Access is denied #29664

guenounrub opened this issue Feb 19, 2025 · 4 comments
Labels
needs: investigation Requires some digging to determine if action is needed

Comments

@guenounrub
Copy link

Command

serve

Is this a regression?

  • Yes, this behavior used to work in the previous version

The previous version in which this bug was not present was

15.2

Description

Angular access denied in C: //

Context

I built an angular app in my personal computer. This app launch a little dashboard so far.

I tried to clone it into my professional computer to have access to some feature. In this computer, I have limited privileges, which means no writings rights on C:.

When I ran npm install, everything went well.

But when I ran npm run start i got the following error

✘ [ERROR] Cannot read directory "../../../../../..": Access is denied. [plugin angular-compiler]
✘ [ERROR] Could not resolve "C:/Users/RGUENOUN/git/other/coreapp-dashboard-feat-register/coreapp-dashboard-feat-register/src/app/pages/registration/registration-form/price-form/price-form.component.scss" [plugin angular-compiler]
✘ [ERROR] Cannot read directory "../../../../../..": Access is denied. [plugin angular-compiler]
✘ [ERROR] Could not resolve "C:/Users/RGUENOUN/git/other/coreapp-dashboard-feat-register/coreapp-dashboard-feat-register/src/app/shared/components/step-bar/step-bar.component.scss" [plugin angular-compiler]
✘ [ERROR] Cannot read directory "../../../../../..": Access is denied. [plugin angular-compiler]
✘ [ERROR] Could not resolve "C:/Users/RGUENOUN/git/other/coreapp-dashboard-feat-register/coreapp-dashboard-feat-register/src/app/shared/components/toaster/toaster.component.scss" [plugin angular-compiler]
✘ [ERROR] Cannot read directory "../../../../../..": Access is denied.

Question

How to fix it ?
And most importantly, why Angular is trying to access on C:// instead of staying in his own folder ??

Other elements

Here is the package.json :

{
  "name": "coreapp-saas-front",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "build-local": "ng build --configuration=local",
    "build-dev": "ng build --configuration=development",
    "local": "ng serve --configuration=local --open --port 5200",
    "dev": "ng serve --configuration=development --open --port 5200",
    "watch": "ng build --watch --configuration development",
    "test": "ng test"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "^18.2.0",
    "@angular/common": "^18.2.0",
    "@angular/compiler": "^18.2.0",
    "@angular/core": "^18.2.0",
    "@angular/forms": "^18.2.0",
    "@angular/platform-browser": "^18.2.0",
    "@angular/platform-browser-dynamic": "^18.2.0",
    "@angular/router": "^18.2.0",
    "@ng-bootstrap/ng-bootstrap": "^17.0.1",
    "@popperjs/core": "^2.11.8",
    "bootstrap": "^5.3.3",
    "bootstrap-icons": "^1.11.3",
    "rxjs": "~7.8.0",
    "tslib": "^2.3.0",
    "zone.js": "~0.14.10"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "^18.2.4",
    "@angular/cli": "^18.2.4",
    "@angular/compiler-cli": "^18.2.0",
    "@angular/localize": "^18.2.0",
    "@types/jasmine": "~5.1.0",
    "jasmine-core": "~5.2.0",
    "karma": "~6.4.0",
    "karma-chrome-launcher": "~3.2.0",
    "karma-coverage": "~2.2.0",
    "karma-jasmine": "~5.1.0",
    "karma-jasmine-html-reporter": "~2.1.0",
    "typescript": "~5.5.2"
  }
}

Other notes

This error also happen when create a project with ng new

Minimal Reproduction

  1. Unzip coreapp-dashboard-main.zip
  2. run npm install
  3. run npm run local
  4. The bug should be reproduced if you have limited access rights

Exception or Error


Your Environment

C:\Users\RGUENOUN\git\other\coreapp-dashboard-main\coreapp-dashboard-main>ng version

     _                      _                 ____ _     ___
    / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
   / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
  / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
 /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
                |___/


Angular CLI: 18.2.4
Node: 22.9.0
Package Manager: npm 10.8.3
OS: win32 x64

Angular: 18.2.4
... animations, cli, common, compiler, compiler-cli, core, forms
... localize, platform-browser, platform-browser-dynamic, router

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1802.4
@angular-devkit/build-angular   18.2.4
@angular-devkit/core            18.2.4
@angular-devkit/schematics      18.2.4
@schematics/angular             18.2.4
rxjs                            7.8.1
typescript                      5.5.4
zone.js                         0.14.10

Anything else relevant?

No response

@alan-agius4 alan-agius4 added the needs: investigation Requires some digging to determine if action is needed label Mar 3, 2025
@VonC
Copy link

VonC commented Mar 17, 2025

For the record, I tried the obvious workaround based on subst, as in subst [<drive1>: [<drive2>:]<path>]

No dice.

C:\Users\me\git\tests\coreapp-dashboard-main\coreapp-dashboard-main>

subst k: C:\me\me\git\tests\coreapp-dashboard-main

C:\Users\me\git\tests\coreapp-dashboard-main\coreapp-dashboard-main>k:

K:\>cd coreapp-dashboard-main

K:\coreapp-dashboard-main>npm run local

> [email protected] local
> ng serve --configuration=local --open --port 5200

Initial chunk files | Names         |  Raw size
styles.css          | styles        | 474.19 kB |
polyfills.js        | polyfills     |  93.00 kB |
scripts.js          | scripts       |   7.47 kB |
main.js             | main          |   1.46 kB |

                    | Initial total | 576.12 kB

Application bundle generation complete. [4.169 seconds]

Watch mode enabled. Watching for file changes...
NOTE: Raw file sizes do not reflect development server per-request transformations.
  ➜  Local:   http://localhost:5200/
  ➜  press h + enter to show help
✘ [ERROR] Cannot read directory "C:/": Access is denied.

I am also on a corporate laptop, with GPO like "Configuration > Administrative Templates > Windows Components > File Explorer > Prevent users from adding files to the root of their users'", similar to this thread.

Question @alan-agius4 : why accessing C:\ in the first place?

@alan-agius4
Copy link
Collaborator

Node.js locates node_modules directories by systematically searching through the folder structure. It begins from the directory where the module is requested and moves upward, checking each parent directory for a node_modules folder. This process continues until it reaches the root of the filesystem. If the module is still not found. For more details, refer to the Node.js module resolution documentation(https://nodejs.org/api/modules.html#modules_all_together).

We should probably mark directories that are inaccessible as non-existent Similar to how it is handled by esbuild evanw/esbuild#938. However, it's unclear whether this issue is related to Angular CLI or another underlying tool.

@VonC
Copy link

VonC commented Mar 17, 2025

@alan-agius4

This process continues until it reaches the root of the filesystem.

I was hoping that, when executed from a "subst'd" drive (here K:), that root of the filesystem would have been K:, which I can read and write into, since it is a folder that I created (C:\me\me\git\tests\coreapp-dashboard-main)

I still don't understand why Node would ever consider anything outside my project structure, though (beside known global folders, or a NODE_PATH that I set and control).
If I maintain a node_modules folder, it should be in my project.
As Ben Nadel described in "Where Does Node.js And Require() Look For Modules?", that search seems overly complex and too broad...

However, it's unclear whether this issue is related to Angular CLI or another underlying tool.

But if the process of “marking directories that are inaccessible as non-existent” something that can be done in Angular, wouldn't that benefit all the other tools using it?

@guenounrub
Copy link
Author

guenounrub commented Mar 18, 2025

It is strange @alan-agius4.
I can run others node projects, not using angular, in my environment !

Moreover, the error happens when I try to run ng serve or ng build.
So it seems to me that is related to angular more than nodejs or node_modules loading ...

For the record, Angular project with version 15 and below are working fine but upper are not working anymore and triggering the problem.

Here is the current config that is encountering the problem:

npm info using [email protected]
npm info using [email protected]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs: investigation Requires some digging to determine if action is needed
Projects
None yet
Development

No branches or pull requests

3 participants