Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I get this error:Cannot find module '@angular-devkit/build-angular/package.json when I try run my app with ng serve from Linux

Tags:

angular

hello guys I have this next error when I try run my App from the terminal(linux), when I run this command:

ng serve

and I get this error in my terminal:

AppBlog/blog# ng serve An unhandled exception occurred: Cannot find module '@angular-devkit/build-angular/package.json' Require stack: - /usr/local/lib/node_modules/@angular/cli/node_modules/@angular-devkit/architect/node/node-modules-architect-host.js - /usr/local/lib/node_modules/@angular/cli/node_modules/@angular-devkit/architect/node/index.js - /usr/local/lib/node_modules/@angular/cli/models/architect-command.js - /usr/local/lib/node_modules/@angular/cli/commands/serve-impl.js - /usr/local/lib/node_modules/@angular/cli/node_modules/@angular-devkit/schematics/tools/export-ref.js - /usr/local/lib/node_modules/@angular/cli/node_modules/@angular-devkit/schematics/tools/index.js - /usr/local/lib/node_modules/@angular/cli/utilities/json-schema.js - /usr/local/lib/node_modules/@angular/cli/models/command-runner.js - /usr/local/lib/node_modules/@angular/cli/lib/cli/index.js - /usr/local/lib/node_modules/@angular/cli/lib/init.js - /usr/local/lib/node_modules/@angular/cli/bin/ng See "/tmp/ng-ev5aDi/angular-errors.log" for further details.

then i checked out this part :

An unhandled exception occurred: Cannot find module '@angular-devkit/build-angular/package.json'

this part say that cannot find moduled called: "'@angular-devkit/build-angular/package.json'"

then I cheked out this file in my project but I have this, look:

  "devDependencies": {     "@angular-devkit/build-angular": "~0.900.3",     "@angular/cli": "~9.0.3",     "@angular/compiler-cli": "~9.0.2",     "@angular/language-service": "~9.0.2",     "@types/node": "^12.11.1",     "@types/jasmine": "~3.5.0",     "@types/jasminewd2": "~2.0.3",     "codelyzer": "^5.1.2",     "jasmine-core": "~3.5.0",     "jasmine-spec-reporter": "~4.2.1",     "karma": "~4.3.0",     "karma-chrome-launcher": "~3.1.0",     "karma-coverage-istanbul-reporter": "~2.1.0",     "karma-jasmine": "~2.0.1",     "karma-jasmine-html-reporter": "^1.4.2",     "protractor": "~5.4.3",     "ts-node": "~8.3.0",     "tslint": "~5.18.0",     "typescript": "~3.7.5"   }

then i went to google and search and I found this like from stackoverflow and I tried their solution but it does not work and I run the command ng serve again.

what I did wrong?

before nothing , before I added 3 components: login,register and home in my folder : src/app with this command : ng generate component login and I import my component in my file : app.component.ts this way:

/* THIS IS JUST A EXAMPLE VERY SIMILAR TO MY CODE REAL,  I just import one component*/  import { Component } from '@angular/core'; import { loginComponent } from './login.component'; @Component({   selector: 'app-root',   templateUrl: './app.component.html',   styleUrls: ['./app.component.css'],   declarations: [loginComponent], //import my login }) export class AppComponent {   title = 'blog'; }

maybe is this part but I dont find a solution, any expert in angular could tell me what I did wrong?

UPDATE

I am continue searching in google and I found this: github/Angular they are saying that I would install npm/angular-cli/node again and I run this command for update my angular cli:

uninstalled ang-cli

npm uninstall @angular/cli

installed the latest

npm install -g @angular/cli@latest

but first I update my npm with this command:

installed the latest npm

npm install -g npm@latest

but it still does not work.

like image 268
simon Avatar asked Feb 25 '20 23:02

simon


People also ask

How fix Cannot find module '@ angular Devkit build angular package JSON?

To solve the error "Could not find module '@angular-devkit/build-angular'", make sure to install the package by opening your terminal in your project's root directory and running the following command: npm i -D @angular-devkit/build-angular and restart your IDE and development server.

Can not find module in angular?

To solve the error "Cannot find module '@angular/core'", make sure you have installed all dependencies by running the npm install command, set the baseUrl option to src in your tsconfig. json file and restart your IDE and development server.

What is angular Devkit build angular used for?

This package contains Architect builders used to build and test Angular applications and libraries.

How do I uninstall angular Devkit schematics?

Please remove both the "node_modules" directory and the package lock file; and then reinstall. If this does not correct the problem, please temporarily install the "@angular-devkit/schematics" package within the workspace. It can be removed once the update is complete.


2 Answers

Please try installing the npm on a project folder. I had installed npm globally but installing the npm once again on a solution folder fixed my issue.

npm install in the project folder will do the trick. Then do ng serve -o

like image 200
Prem2530 Avatar answered Sep 18 '22 19:09

Prem2530


I finally found something working for me.

Add --force at the end of your npm command.

Like npm install --save-dev @angular-devkit/build-angular --force

Then ng serve

like image 34
Ben Avatar answered Sep 21 '22 19:09

Ben