angular - ng 服务抛出错误 "The serve command requires to be run in an Angular project, but a project definition could not be found"

标签 angular

我需要运行该项目并在本地主机上访问它。当我从 gitlab 下载该项目并将其解压缩时,它抛出一个警告,指出本地和全局 CLI 包不匹配。然后我将本地CLI版本升级到7.1.1。从那时起它就抛出这个错误。是全局和本地 CLI 包的问题吗?

我什至将全局和本地 CLI 版本降级到 1.7.4。它抛出 ng command not found 错误。我的项目文件夹中有 .angular-cli.jsonpackage.json 中的 @angular/cli 是 7.1.1。

当我从命令行运行 ngserve 时,出现以下错误:

    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.

我无法修复它。以下是我更新 Angular CLI 全局和本地版本所遵循的步骤

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

要将 Angular CLI 更新到新版本,您必须更新全局包和项目的本地包。

    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

您能帮忙解决这个错误吗?

请找到下面的项目目录结构截图:它包含 .angular-cli.jsonpackage.json 文件。

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

当我运行 npm install 而不更新任何内容时,出现以下错误:

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

当我在 npm install 后运行 ngserve 而不更新任何内容时,出现以下错误:

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

最佳答案

看来您还没有将项目迁移到版本 7。新的 Angular cli 使用 angular.json 而不是 .angular-cli.json 进行配置。

关注migration guide .

关于angular - ng 服务抛出错误 "The serve command requires to be run in an Angular project, but a project definition could not be found",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53625195/

相关文章:

Angular 5 -> Angular 6 Rxjs .map() 到 .pipe(map())

angular - Nginx for Angular没有达到后端api

Angular4 - 新产品数量(数量)不与之前的数量相加

angular - 刷新 ListView 在运行时在 NativeScript 和 Angular 中添加新元素

html - 如果我在标签中提供路由器链接,bootstrap 4 中的导航选项卡将无法正常工作

angularjs - 注入(inject)的服务在构造函数中未定义

angular - 在 angular2 的自定义管道上扩展管道,如货币或数字

angular - 如何使用 Angular 作为 Material 将动画设置为 Nebular Stepper

angular - node_modules/@ngrx/store/src/models.d.ts(58,58) : error TS2304: Cannot find name 'unknown' 中的错误

html - Angular 点击事件绑定(bind)无法正常工作