Angular CLI错误:找不到项目定义

时间:2019-05-18 13:32:17

标签: angular angular-cli

我正在尝试运行由同事创建的Angular程序。我遇到了同样的错误,“ serve命令需要在Angular项目中运行,但是找不到项目定义。” 这是在运行“ npm install”和“ npm start”命令之后,尽管遵循了我能找到的所有建议。

我的软件信息: Angular CLI:7.3.9 节点:10.15.3 操作系统:Darwin x64 角度:7.2.15 @角度/ cli 7.3.9 打字稿3.2.4

注意:在package.json文件中,其内容如下所示,以表明“ ng start”脚本是使用ng serve命令运行的(据我所知)。

 {
  "name": "twitter-api",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "~7.2.0",
    "@angular/common": "~7.2.0",
    "@angular/compiler": "~7.2.0",
    "@angular/core": "~7.2.0",
    "@angular/forms": "~7.2.0",
    "@angular/platform-browser": "~7.2.0",
    "@angular/platform-browser-dynamic": "~7.2.0",
    "@angular/router": "~7.2.0",
    "body-parser": "^1.18.3",
    "core-js": "^2.5.4",
    "express": "^4.16.4",
    "rxjs": "~6.3.3",
    "tar": "^4.4.8",
    "tslib": "^1.9.0",
    "twit": "^2.2.11",
    "underscore": "^1.9.1",
    "zone.js": "~0.8.26"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~0.13.0",
    "@angular/cli": "~7.3.7",
    "@angular/compiler-cli": "~7.2.0",
    "@angular/language-service": "~7.2.0",
    "@types/node": "~8.9.4",
    "@types/jasmine": "~2.8.8",
    "@types/jasminewd2": "~2.0.3",
    "codelyzer": "~4.5.0",
    "jasmine-core": "~2.99.1",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~4.0.0",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~2.0.1",
    "karma-jasmine": "~1.1.2",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.4.0",
    "ts-node": "~7.0.0",
    "tslint": "~5.11.0",
    "typescript": "~3.2.2"
  },
  "description": "This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 7.3.7.",
  "main": "index.js",
  "author": "Remington Lee",
  "license": "ISC"
}

注意:仅当我运行“ ng start”命令时,才会出现以下错误。如果我使用“ ng serve”命令,则错误很简单,即“ serve命令需要在Angular项目中运行,但找不到项目定义。”

Leonas-MacBook-Air:TwitterAPI-master leonaadriennestephanieponce$ npm start

> twitter-search-api-erl@1.0.0 start /Users/leonaadriennestephanieponce/Downloads/TwitterAPI-master
> node ./node-server/index.js

/Users/leonaadriennestephanieponce/Downloads/TwitterAPI-master/node_modules/twit/lib/twitter.js:511
      throw new Error(err_msg)
      ^

Error: Twit config must include `consumer_key` when using user auth.
    at /Users/leonaadriennestephanieponce/Downloads/TwitterAPI-master/node_modules/twit/lib/twitter.js:511:13
    at Array.forEach (<anonymous>)
    at Twitter._validateConfigOrThrow (/Users/leonaadriennestephanieponce/Downloads/TwitterAPI-master/node_modules/twit/lib/twitter.js:508:17)
    at new Twitter (/Users/leonaadriennestephanieponce/Downloads/TwitterAPI-master/node_modules/twit/lib/twitter.js:58:8)
    at Object.<anonymous> (/Users/leonaadriennestephanieponce/Downloads/TwitterAPI-master/node-server/twitterService.js:7:11)
    at Module._compile (internal/modules/cjs/loader.js:701:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
    at Module.load (internal/modules/cjs/loader.js:600:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:539:12)
    at Function.Module._load (internal/modules/cjs/loader.js:531:3)
    at Module.require (internal/modules/cjs/loader.js:637:17)
    at require (internal/modules/cjs/helpers.js:22:18)
    at Object.<anonymous> (/Users/leonaadriennestephanieponce/Downloads/TwitterAPI-master/node-server/index.js:3:24)
    at Module._compile (internal/modules/cjs/loader.js:701:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
    at Module.load (internal/modules/cjs/loader.js:600:32)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! twitter-search-api-erl@1.0.0 start: `node ./node-server/index.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the twitter-search-api-erl@1.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/leonaadriennestephanieponce/.npm/_logs/2019-05-18T13_37_33_583Z-debug.log
Leonas-MacBook-Air:TwitterAPI-master leonaadriennestephanieponce$ 

我尝试了以下建议:
    -验证根文件夹
    -验证angular.json和angular-cli.json文件是否存在
    -验证TS版本的兼容性
    -更新当前的角度cli

  

ng更新@ angular / cli-仅迁移--from =      (也通过ng update --all --force)

-卸载/重新安装/验证缓存

  

npm卸载-g @ angular / cli
  npm缓存验证
  npm install -g @ angular / cli @ latest

由于某些原因,尽管我付出了很多努力,但我仍遇到Angular软件和相关软件包的问题。

任何其他建议,我们将不胜感激!

2 个答案:

答案 0 :(得分:0)

随着错误的出现

Error: Twit config must include `consumer_key` when using user auth.
at /Users/leonaadriennestephanieponce/Downloads/TwitterAPI-master/node_modules/twit/lib/twitter.js:511:13

您是否在twit Twitter api调用配置中提供了consumer_key?否则,它将在正确命名的函数_validateConfigOrThrow中引发错误。 511行也适用于此:check source code of twit

答案 1 :(得分:0)

这对我有用

npm卸载@ angular / cli npm缓存验证 npm install -g @ angular / cli