37

An unhandled exception occurred:

ENOENT: no such file or directory, lstat 
'/Users/Desktop/node_modules'
See "/private/var/folders/3p/l_k1wk8n76v3cfwnxk0blx000000gn/T/ng- 
DF5EZ7/angular-errors.log" for further details.

Whenever i am doing ng serve, this error occurs, Can anyone tell me what is the cause of error. stuck in this since long hours.

Daniel B
  • 8,770
  • 5
  • 43
  • 76
shristy sinha
  • 379
  • 1
  • 3
  • 3
  • Are you running the command in the root of your project folder? – Daniel B Mar 12 '21 at 10:15
  • yes, previously it was running, after some when again i did ng serve , this error is showing, i had to create new project but in that too after another ng serve this same error occuring, why this is happening. – shristy sinha Mar 12 '21 at 10:38
  • if your project can be uploaded to github or somewhere else that would be the best, but the error may persint in the package.json file. Please try to rerunn npm install again – Richárd Baldauf Mar 12 '21 at 11:30
  • I got that error, but was because I had an additional console running "ng serve". – a52 Apr 11 '22 at 17:58

26 Answers26

66

I had this problem, it was just:

  1. Works "styles": [ "node_modules/bootstrap/dist/css/bootstrap.min.css"

  2. Not works "styles": [ "../node_modules/bootstrap/dist/css/bootstrap.min.css"

30

I had the same error when I tried installing an old version of bootstrap and referenced it in the angular.json file. Meanwhile, the package was never installed because it doesn't exist anymore. Check the new command for installing a particular package and after doing npm i <package-name> check in node_modules if it's there.

And also, I changed my bootstrap path from

../node_modules/bootstrap/dist/css/bootstrap.css

to

node_modules/bootstrap/dist/css/bootstrap.css
F.zehra
  • 87
  • 8
Elvis020
  • 410
  • 3
  • 6
7

In my case, my problem was a misspelling issue in the directory URL inside Angular.json. So I corrected the error and the apps run perfectly afterwards.

Not working: (misspelled on "node_modules")

"styles": ["./node_moodules/font-awesome/css/font-awesome.css"]

Working:

"styles": ["./node_modules/font-awesome/css/font-awesome.css"]

try checking your url path in Angular.json, this probably the case, hopefully this helps!

Synth Sloth
  • 126
  • 4
  • 14
6

I got into this issue after installing ngx-bootstrap

> ng add ngx-bootstrap

Following went in angular.json

"styles": [
 "./dist/ngx-bootstrap/datepicker/bs-datepicker.css",
 "./node_modules/bootstrap/dist/css/bootstrap.min.css",
 "src/styles.css"
]

Changed to following and error got fixed

"styles": [
  "node_modules/ngx-bootstrap/datepicker/bs-datepicker.css",
  "node_modules/bootstrap/dist/css/bootstrap.min.css",
  "src/styles.css"
]
learning...
  • 3,104
  • 10
  • 58
  • 96
3

Solving the problems on angular.json then deleting package-lock.json solved my problem.

My problem was related to a deleted package @angular/material. Angular.json styles were still referencing that package, I deleted those lines. Then I deleted the package-lock.json and execute it.

F.zehra
  • 87
  • 8
3

Just do:

npm install --force and then npm audit fix --force

2

I had the same problem. But I found a Solution which works for me.

Try:

npm install --save bootstrap

and then add in angular.json at "styles":

"node_modules/bootstrap/dist/css/bootstrap.min.css"

run the Project (Watch if youre in the right folder you can check it with typing in terminal ls and and then you should see node_modules, src etc.)

ng serve

Dopaemin
  • 37
  • 8
2

if: npm install bootstrap then "./node_modules/bootstrap/dist/css/bootstrap.min.css"

if npm install --save bootstrap then "node_modules/bootstrap/dist/css/bootstrap.min.css"

akSingh
  • 21
  • 2
2

I was facing similar error:

 An unhandled exception occurred: ENOENT: no such file or directory, lstat 
'C:\User_Name\Angular\node_modules\bootstrap'
See "C:\Users\User_Name\AppData\Local\Temp\ng-MhR1Ls\angular-errors.log" for further details.

This was caused due to adding this in styles array:

    "styles": [
          "src/styles.css",
          "../node_modules/bootstrap/dist/css/bootstrap.min.css"
        ]

Solved it by changing styles array with

    "styles": [
          "src/styles.css",
          "node_modules/bootstrap/dist/css/bootstrap.min.css"
        ]

This may have happened cause I made another angular project inside the parent folder or directory since "." denotes the home directory. This is just my understanding and the solution of the issue.

Please check whether you have added your current component.html file i.e. unique selector in your app.component.html file

Recently started my angular journey so cheers!!

Ashutosh
  • 21
  • 2
1

As @Manuel Villadiego said, you must define your bootstrap path like below:

"node_modules/bootstrap/dist/css/bootstrap.min.css"

Or

"./node_modules/bootstrap/dist/css/bootstrap.min.css"

This error will happen when you start bootstrap path with ../ ,

"../node_modules/bootstrap/dist/css/bootstrap.min.css"

because you go back one folder and node_modules folder doesn't exist there.

Abbas Jafari
  • 1,492
  • 2
  • 16
  • 28
1

I'm had the same problem with my angular project after installing Boostrap.

My approach was:

angular.json file should have this under styles. "./node_modules/bootstrap/dist/css/bootstrap.min.css", "src/styles.css"

Then import in the main style.css file.

@import url('../node_modules/bootstrap/dist/css/bootstrap.min.css');

Make sure the path for node_modules is correct,

After making those changes I ran ng serve or npm start Angular app is running

1

check angular.json file. sometimes style css pointing to the node modules may be incorrect

 "styles": [
 "./node_modules/@angular/material/prebuilt-themes/indigo-pink.css",
              "src/styles.scss",
              "node_modules/primeicons/primeicons.css",
              "node_modules/primeng/resources/themes/lara-light-blue/theme.css",
              "node_modules/primeng/resources/primeng.min.css"
        ],
Ashik T M
  • 23
  • 1
  • 7
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Apr 14 '22 at 02:55
1

I think the issue could be one of many flavors. Mine was specifically, in the relative path of bootstrap.min.css that was specified in angular.json

The error message that I had in the logs was:
"[error] Error: ENOENT: no such file or directory, lstat 'C:\Users\arsth\node_modules'"

I was following a tutorial video and provided the path as ../node_modules/bootstrap/dist/css/bootstrap.min.css.

But in my project, the angular.json file is actually at the same level as the node_modules folder. So correcting the above entry to ./node_modules/bootstrap/dist/css/bootstrap.min.css solved the issue.

Philippe
  • 861
  • 10
  • 10
suramana
  • 43
  • 1
  • 5
0
  1. Download manually bootstrap from https://www.npmjs.com/package/bootstrap .
  2. Copy and past the folder you download to /Users/Desktop/node_modules .
  3. In CMD, enter to your project folder you created by typing: CD yourProjectName .
  4. In CMD: ng serve.
  5. In your browser: http://localhost:4200/
0

In my case i removed the "../node_modules/bootstrap/dist/css/bootstrap.min.css" from angular.json

Breno AllenCS
  • 573
  • 3
  • 8
0

I had this problem on a non-Angular project; here's what worked for me:

  1. update node and npm
  2. delete package-lock.json
  3. run npm install --package-lock-only
nydame
  • 324
  • 4
  • 8
0

Usually, it happens when

package-lock.json

was created by another version of the node js (I'm using the latest LTS version).

Just remove it and try again, this is OK.

0

I just had the same issue, I removed the followings from angular.json which I had just added and the issue is resolved.

          "./node_modules/@angular/material/prebuilt-themes/indigo-pink.css",
          "src/styles/styles.scss",
          "src/styles/colors.scss"
CodeLearner
  • 115
  • 2
  • 7
0

Step 1) npm install --save bootstrap

Step 2) and then add in angular.json at "styles": "./node_modules/bootstrap/dist/css/bootstrap.min.css",

Step 3) ng serve

Problem solved

image showing the solution

Suraj Rao
  • 29,388
  • 11
  • 94
  • 103
iOSDeveloper
  • 475
  • 1
  • 3
  • 7
0

I removed the file from angular.json and added it to style.css.

@import '../node_modules/ngx-bootstrap/datepicker/bs-datepicker.css'
RiveN
  • 2,595
  • 11
  • 13
  • 26
Gustavo
  • 11
  • 1
0

Angular.js & Wrong Directions.

First of all, open a file called angular.js in the root folder.

And check if you add some wrong Directory. like the style or something like that. as example.

Suppose you add the bootstrap dependency and you want to add it to your project you will go to the angular.js and add it in the style configuration. so you will add it as the below:

 "styles": [
              "../node_modules/bootstrap/dist/css/bootstrap.min.css",
              "src/styles.css"
            ],

Check if you add double dot .. not one dot in the path like the below:

"../node_modules/bootstrap/dist/css/bootstrap.min.css",

Correct format is as the below :

"./node_modules/bootstrap/dist/css/bootstrap.min.css",
Abd Abughazaleh
  • 4,615
  • 3
  • 44
  • 53
0

In the angular.json file just do this change :

"styles" : [ "node_modules/bootstrap/dist/css/bootstrap.min.css", "src/styles.css" ]

Mounesh
  • 561
  • 5
  • 18
0

remove all node_module or remove node_moules folder and type npm install

user2308728
  • 91
  • 1
  • 2
0

Bumped against the same issue with the quickstart tutorial. After restarting the tutorial and using yarn instead of npm, everything seems working fine.

haddassah S
  • 147
  • 1
  • 7
0

On my project, I use bootstrap with SCSS and changing the path from "node_modules/bootstrap/dist/scss/bootstrap.scss" to "node_modules/bootstrap/scss/bootstrap.scss" helped me with this error.

PS. I deleted the dist folder from path.

-2

You need to check with the path of bootstrap in angular.json inside architect then styles

  • Please answer with examples or more guidance – adrisons May 21 '21 at 07:23
  • We appreciate your vague and generic answer mate. - Next time kindly be elaborate as what path should be edited from what to what. You go ahead and finish, ...`then styles`, Which styles dude? Anyways, thank you. – Jacob Okello Okomo Nov 25 '22 at 09:34