I am trying to run an Angular program created by a colleague. I am getting the same error, “The serve command requires to be run in an Angular project, but a project definition could not be found.” This was after running the “npm install” and “npm start” commands despite following every suggestion I could find.
My Software info:
Angular CLI: 7.3.9
Node: 10.15.3
OS: darwin x64
Angular: 7.2.15
@angular/cli 7.3.9
typescript 3.2.4
Note: In the package.json file it reads as directly below to indicate “ng start” script is run with the ng serve command (to my understanding).
{
"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"
}
Note: This error below only presents when I run the “ng start” command. If I use the “ng serve” command, the error is simply, “The serve command requires to be run in an Angular project, but a project definition could not be found.”
Leonas-MacBook-Air:TwitterAPI-master leonaadriennestephanieponce$ npm start
> [email protected] 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! [email protected] start: `node ./node-server/index.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] 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$
I have tried these suggestions:
-Verify root folder
-Verify presence of both angular.json and angular-cli.json files
-Verify compatibility of TS version
-Updating current angular cli
ng update @angular/cli –migrate-only –from=
(also via ng update –all –force)
-Uninstall/reinstall/verify cache
npm uninstall -g @angular/cli
npm cache verify
npm install -g @angular/cli@latest
For some reason I am having issues with the Angular software and associated packages despite my efforts.
Any further suggestions are much appreciated!
2
Answers
As the error prints
did you provide consumer_key in your twit Twitter api call config? Else it will throw error in the rightly named function _validateConfigOrThrow.
Line 511 would fit to this as well: check source code of twit
This worked for me
npm uninstall @angular/cli
npm cache verify
npm install -g @angular/cli