I took me 10 hours of investigatons to find this:
npm start
The long story to let you compare your investigation approach:
After multiple failed attempts I reinstalled the node and npm and now I have:
c:\> ng -v
@angular/cli: 1.3.0
node: 6.9.0
os: win32 ia32
All works fine for new projects
ng new my-new-project
But I have a compromized project that shows
Unable to find "@angular/cli" in devDependencies.
Please take the following steps to avoid issues:
"npm install --save-dev @angular/cli@latest"
The "@angular/compiler-cli" package was not properly installed. Error: Error: Cannot find module '@angular/compiler-cli'
Error: The "@angular/compiler-cli" package was not properly installed. Error: Error: Cannot find module '@angular/compiler-cli'
at Object.<anonymous> (C:\Users\profimedica\AppData\Roaming\npm\node_modules\@angular\cli\node_modules\@ngtools\webpack\src\index.js:14:11)
Because I already have @angular/cli installed globally, I just had to add it to the package.json file, using as example the same file from a new created project that works fine:
{
"dependencies": {
"body-parser": "^1.17.1",
"express": "^4.15.2",
"http": "0.0.0"
},
"devDependencies": {
"@angular/cli": "1.3.0",
"@angular/compiler-cli": "^4.2.4"
}
}
The second error is thrown from here because the @angular/compiler-cli module is not installed as a local module:
// Check that Angular is available.
try {
version = require('@angular/compiler-cli').VERSION;
}
catch (e) {
throw new Error('The "@angular/compiler-cli" package was not properly installed. Error: ' + e);
}
I checked the node_modules folder and I observed that the folders .\node_modules\@angular\compiler-cli, .\node_modules\@angular\compiler and .\node_modules\@angular\core where missing.
I installed as required:
npm install @angular/compiler-cli
npm install @angular/compiler
npm install @angular/core
I added a log to the file and I see detected version after install: .\node_modules\@ngtools\webpack\src\index.js
console.log(require('@angular/compiler-cli').VERSION);
Version { full: '4.3.5' }
Now I get a new error:
Cannot read property 'config' of null
TypeError: Cannot read property 'config' of null
at Class.run (C:\PRO\htdocs\my\api\gen\projects\generated\testknowledge\node_modules\@angular\cli\tasks\serve.js:23:63)
To investigate this new issue I added a log line in .\node_modules\@angular\cli\models\config\config.js
class CliConfig {
constructor(_configPath, schema, configJson, fallbacks = []) {
this._configPath = _configPath;
console.log(_configPath);
this._config = new (json_schema_1.SchemaClassFactory(schema))(configJson, ...fallbacks);
}
And I got the unexpected value:
C:\Users\profimedica\.angular-cli.json
Obviously, this file is not in my home directory, instead of from the root of the project:
.\angular-cli.json
After 3 hours of investigations and attempts to create the missing files I had to rethink the approach.
I deleted the local @angular module and reinstalled globally:
npm install --save-dev @angular/cli@latest
npm install --save-dev @angular/compiler-cli@latest
npm install --save-dev @angular/compiler@latest
npm install --save-dev @angular/core@latest
I found that my project has a custom architecture and I had to run
npm start