Mrunalini
Mrunalini

Reputation: 59

ng serve throws error "The serve command requires to be run in an Angular project, but a project definition could not be found"

I need to run the project and access it on localhost. When I downloaded the project from gitlab and unzipped it it threw a warning that local and global CLI packages do not match. Then I upgraded the local CLI version to 7.1.1. It is throwing this error since then. Is it a problem with the global and local CLI packages?

I even downgraded the global and local CLI versions to 1.7.4. It is throwing ng command not found error. I have .angular-cli.json in my project folder and @angular/cli in package.json is 7.1.1.

I am getting the below error when I run ng serve from the command line:

    C:\Users\mrunalini.prasad\Desktop\fsacademy\fsacademy-master>ng serve
    The serve command requires to be run in an Angular project, but a project definition could not be found.

I am unable to fix it. Below are the steps that I have followed to update my angular CLI global and local versions

    npm uninstall -g angular-cli
    npm uninstall --save-dev angular-cli

To update Angular CLI to a new version, you must update both the global package and your project's local package.

    Global package:

    npm uninstall -g @angular/cli
    npm cache clean
    npm install -g @angular/cli@latest
    Local project package:

    rmdir node_modules on Windows
    npm install --save-dev @angular/cli@latest
    npm install

    ng --version is giving the below output:

    C:\Users\mrunalini.prasad\Desktop\fsacademy\fsacademy-master>ng --version

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


    Angular CLI: 7.1.1
    Node: 10.10.0
    OS: win32 x64
    Angular: 4.4.7
    ... animations, common, compiler, compiler-cli, core, forms
    ... http, platform-browser, platform-browser-dynamic, router
    ... tsc-wrapped

    Package                      Version
    ------------------------------------------------------
    @angular-devkit/architect    0.11.1
    @angular-devkit/core         7.1.1
    @angular-devkit/schematics   7.1.1
    @angular/cdk                 5.2.5
    @angular/cli                 7.1.1
    @angular/flex-layout         2.0.0-rc.1
    @angular/material            2.0.0-beta.5
    @schematics/angular          7.1.1
    @schematics/update           0.11.1
    rxjs                         5.5.12
    typescript                   2.3.4

Can you please help resolve this error?

Please find the screenshot of project directory structure below: It has the .angular-cli.json and package.json files.

Directory of C:\Users\mrunalini.prasad\Desktop\fsacademy\fsacademy-master

12/05/2018  09:47 AM    <DIR>          .
12/05/2018  09:47 AM    <DIR>          ..
12/03/2018  03:24 PM             1,060 .angular-cli.json
12/03/2018  03:24 PM               245 .editorconfig
12/04/2018  03:12 PM    <DIR>          .vscode
12/03/2018  03:24 PM             2,272 app.component.ts
12/04/2018  03:12 PM    <DIR>          backup
12/05/2018  09:47 AM    <DIR>          node_modules
12/05/2018  09:47 AM           149,659 package-lock.json
12/04/2018  05:11 PM             1,299 package.json
12/03/2018  03:24 PM             1,397 package.json.2
12/03/2018  03:24 PM             3,427 README.md
12/04/2018  03:14 PM    <DIR>          src
12/04/2018  03:14 PM    <DIR>          steps
12/03/2018  03:24 PM               431 tsconfig.json
12/03/2018  03:24 PM             2,710 tslint.json
12/04/2018  03:14 PM    <DIR>          workshop-cli
12/03/2018  03:24 PM           174,967 yarn.lock
              10 File(s)        337,467 bytes
               8 Dir(s)  89,720,467,456 bytes free

I am getting the below error when I run npm install without updating anything:

gyp ERR! stack Error: Can't find Python executable "python", you can set the PYT
HON env variable.
gyp ERR! stack     at PythonFinder.failNoPython (C:\Users\mrunalini.prasad\Deskt
op\fsacademydemo\fsacademy-master\node_modules\node-gyp\lib\configure.js:484:19)

gyp ERR! stack     at PythonFinder.<anonymous> (C:\Users\mrunalini.prasad\Deskto
p\fsacademydemo\fsacademy-master\node_modules\node-gyp\lib\configure.js:509:16)
gyp ERR! stack     at C:\Users\mrunalini.prasad\Desktop\fsacademydemo\fsacademy-
master\node_modules\graceful-fs\polyfills.js:282:31
gyp ERR! stack     at FSReqWrap.oncomplete (fs.js:154:21)
gyp ERR! System Windows_NT 6.3.9600
gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\mrunalini.pra
sad\\Desktop\\fsacademydemo\\fsacademy-master\\node_modules\\node-gyp\\bin\\node
-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_l
dflags=" "--libsass_library="
gyp ERR! cwd C:\Users\mrunalini.prasad\Desktop\fsacademydemo\fsacademy-master\no
de_modules\node-sass
gyp ERR! node -v v10.10.0
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok

I am getting the below error when I run ng serve after npm install without updating anything:

ERROR in ./node_modules/raw-loader!./node_modules/postcss-loader/lib??embedded!.
/node_modules/sass-loader/lib/loader.js??ref--8-3!./src/theme.scss
Module build failed: Error: Cannot find module 'node-sass'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:581:15)
    at Function.Module._load (internal/modules/cjs/loader.js:507:25)
    at Module.require (internal/modules/cjs/loader.js:637:17)
    at require (internal/modules/cjs/helpers.js:20:18)
    at Object.<anonymous> (C:\Users\mrunalini.prasad\Desktop\fsacademydemo\fsaca
demy-master\node_modules\sass-loader\lib\loader.js:3:14)
    at Module._compile (internal/modules/cjs/loader.js:689:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
    at Module.load (internal/modules/cjs/loader.js:599:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
    at Function.Module._load (internal/modules/cjs/loader.js:530:3)
    at Module.require (internal/modules/cjs/loader.js:637:17)
    at require (internal/modules/cjs/helpers.js:20:18)
    at loadLoader (C:\Users\mrunalini.prasad\Desktop\fsacademydemo\fsacademy-mas
ter\node_modules\loader-runner\lib\loadLoader.js:13:17)
    at iteratePitchingLoaders (C:\Users\mrunalini.prasad\Desktop\fsacademydemo\f
sacademy-master\node_modules\loader-runner\lib\LoaderRunner.js:169:2)
    at iteratePitchingLoaders (C:\Users\mrunalini.prasad\Desktop\fsacademydemo\f
sacademy-master\node_modules\loader-runner\lib\LoaderRunner.js:165:10)
    at C:\Users\mrunalini.prasad\Desktop\fsacademydemo\fsacademy-master\node_mod
ules\loader-runner\lib\LoaderRunner.js:173:18

Upvotes: 2

Views: 27452

Answers (2)

R. Viral
R. Viral

Reputation: 396

If you don't want to update anything and just want to run then follow bellow steps,

  • update global version of angular npm install @angular/cli -g
  • take fresh clone in another folder (because after use --save your package.json was change)
  • use npm install and now you getting mismatch error
  • just use this ng config -g cli.warnings.versionMismatch false

i hope this will help.

Upvotes: 0

Henry
Henry

Reputation: 43738

It seems you did not migrate your project to version 7 yet. The new angular cli uses angular.json and not .angular-cli.json for its configuration.

Follow the migration guide.

Upvotes: 3

Related Questions