angular-cli: TypeError: Cannot read property 'config' of null

Please provide us with the following information:

OS?

Windows 7

Versions.

Please run ng --version. If there’s nothing outputted, please run in a Terminal: node --version and paste the result here:

@angular/cli: 1.0.0-beta.31
node: 6.9.4
os: win32 x64
@angular/cli: 1.0.0-beta.31
@angular/common: 2.2.4
@angular/compiler: 2.2.4
@angular/compiler-cli: 2.4.7
@angular/core: 2.4.7
@angular/forms: 2.2.4
@angular/http: 2.2.4
@angular/platform-browser: 2.2.4
@angular/platform-browser-dynamic: 2.2.4
@angular/router: 3.2.4
@angular/upgrade: 2.2.4

Repro steps.

Was this an app that wasn’t created using the CLI? What change did you do on your code? etc.

Added cli later and did ng init

The log given by the failure.

Normally this include a stack trace and some more information.

ng build --prod --verbose
Cannot read property 'config' of null
TypeError: Cannot read property 'config' of null
   at Class.run (C:\Projects\Someplace\Portal\Someplace\node_modules\@angular\cli\tasks\build.js:14:89)
   at Class.run (C:\Projects\Someplace\Portal\Someplace\node_modules\@angular\cli\commands\build.js:49:26)
   at Class.<anonymous> (C:\Projects\Someplace\Portal\Someplace\node_modules\@angular\cli\ember-cli\lib\models\command.js:134:17)
   at process._tickCallback (internal/process/next_tick.js:103:7)

Mention any other details that might be useful.

The offending line const outputPath = runTaskOptions.outputPath || config_1.CliConfig.fromProject().config.apps[0].outDir;


Thanks! We’ll be in touch soon.

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 42
  • Comments: 62 (2 by maintainers)

Commits related to this issue

Most upvoted comments

guys i found the solution ! 😄 in my case i moved the project to another directory there is a hidden file called .angular-cli show the hidden file in the old project and copy this file and past it in the new distention . this is solved the issue for me .

Since I’m working on a pretty new repo, I just recreated from scratch using Angular CLI this time and everything is working for me. ¯_(ツ)_/¯

Guys, quickest solution is to do this $ sudo rm -rf node_modules $ npm install $ ng serve

I know why it is happening but I don’t know how to solved. The problem is that the transpiled JS code remove the “.” at the beginning of the string “.angular-cli.json”, so angular-cli cannot find the configuration file because it is looking for a file that doesn’t exist. Let me show you:

This is the content of packages/@angular/cli/models/config.ts:

(...)
import * as chalk from 'chalk';
import * as fs from 'fs';
import * as path from 'path';

export const CLI_CONFIG_FILE_NAME = '.angular-cli.json';
const CLI_CONFIG_FILE_NAME_ALT = 'angular-cli.json';
(..)

As you can see, the variable CLI_CONFIG_FILE_NAME stores the name of the angular-cli configuration file that is in the root path of your project. However, once you create a new project with angular-cli, the same variable has another value:

node_modules/@angular/cli/models/config.js

(...)
const chalk = require('chalk');
const fs = require('fs');
const path = require('path');
exports.CLI_CONFIG_FILE_NAME = 'angular-cli.json';
function _findUp(name, from) {
(...)

The “.” of “.angular-cli.json” has gone. This is the reason why we are getting a null in the config, because angular-cli is looking for ‘angular-cli.json’ but the real file is .angular-cli.json. I don’t know why it is happening. My guess is that there is a problem with the TypeScript configuration but I’m not sure.

The workaround is easy. First, change the name of the “.angular-cli.json” in the root folder for “angular-cli.json”. After that, add the property app.environments.sorce with the relative path of the environment configuration file that you want use by default:

"environments": {
        "source": "environments/environment.ts",
        "dev": "environments/environment.ts",
        "prod": "environments/environment.prod.ts"
 }

I hope this helps.

you must have .angular-cli.json it use my one day

We had the same problem after updating to an RC version of cli from beta. We were running the project in an ubuntu docker image on a CI. Because .angular-cli.json is considered a hidden file in linux, it was not copied to the image originally. shopt -s dotglob before copying solved the issue.

I had the same issue but solved it by running, (ng init): ./node_modules/.bin/ng init

Then you will get questions regarding which files to overwrite and which to keep.

After that I could run, (ng build): ./node_modules/.bin/ng build without any problems.

Well, did anyone in this thread mentioned it is because .angular-cli.json is a hidden file and it is lost when you move your project to another folder? Did anyone or it is just me first? 😉

@soodvarun @ardiadrianadri @bougnat12 @jdschmitt @dpalita

Guys first of all try to check whether the the given file is there or not in the below project specified path. file name : .angular-cli.json note :

  1. This .angular-cli.json file should must be there. It should be .angular-cli.json only,not like (_ angular-cli.json) or anything else.

Check the screenshot 👍

image

The reason why it is showing error is basically due to above two mentioned points :

image

I hope it may help you guys!! 👍 😃

@HDaghash, Thanks! copying .angular-cli.json from an old project to the new worked!

This is a really bad error message.

Guys you maybe moved your files to another subdirectory.

Those, who have this problem: try to wipe node_modules directory. Helped me locally. Maybe some old and cached by the server dependencies caused this. But not working when deploying to heroku:

...
2017-03-15T23:09:57.879827+00:00 app[web.1]: > ng serve
2017-03-15T23:09:57.879828+00:00 app[web.1]:
2017-03-15T23:09:59.951036+00:00 heroku[web.1]: Process exited with status 1
2017-03-15T23:09:59.950350+00:00 heroku[web.1]: State changed from starting to crashed
2017-03-15T23:09:59.857740+00:00 app[web.1]: TypeError: Cannot read property 'config' of null
2017-03-15T23:09:59.857156+00:00 app[web.1]: Cannot read property 'config' of null
2017-03-15T23:09:59.857741+00:00 app[web.1]:     at Class.run (/app/node_modules/@angular/cli/tasks/serve.js:22:63)
2017-03-15T23:09:59.857743+00:00 app[web.1]:     at check_port_1.checkPort.then.port (/app/node_modules/@angular/cli/commands/serve.js:103:26)
2017-03-15T23:09:59.857743+00:00 app[web.1]:     at process._tickCallback (internal/process/next_tick.js:103:7)
2017-03-15T23:09:59.873249+00:00 app[web.1]:
2017-03-15T23:09:59.880433+00:00 app[web.1]: npm ERR! Linux 3.13.0-112-generic
2017-03-15T23:09:59.880633+00:00 app[web.1]: npm ERR! argv "/app/.heroku/node/bin/node" "/app/.heroku/node/bin/npm" "start"
2017-03-15T23:09:59.880796+00:00 app[web.1]: npm ERR! node v7.6.0
2017-03-15T23:09:59.880936+00:00 app[web.1]: npm ERR! npm  v4.1.2
2017-03-15T23:09:59.881064+00:00 app[web.1]: npm ERR! code ELIFECYCLE
...

wiping cache doesn’t help in this case

I know how to resolve this issue. At the time of moving files from one folder to another, there is a hidden file .angular-cli.json. paste it into new folder. It works for me.

Heya all, I believe this must be a problem on your cli configs. There must be some kind of outdated entry there, or maybe you’re using an old version of the CLI.

Have a look at https://github.com/angular/angular-cli/wiki/stories-rc-update to see how to update your project.

If someone can provide me with a repro that I can follow to see this error, I can look at it further.

hello guys, I think this is the simple problem we are ignored: in this case, when I moved the project one directory to another directory there is some hidden file called like::::::".angular-cli ", “.editorconfig”. show the hidden file in the old project and copy this file and past it in the new distention. this is solved the issue for me. or any other angular project or create a new project then copy the hidden file and past it in the new destination

it’s happened to me several times. All of them, the problem was I had moved the project to different folders, and I did it through files/finder/explorer, so some hidden files weren’t copied. try removing the new project, and copying it with the command line. worked awesome for me.

@HDaghash, it works for me!! thanks. In my case I have created it, with ng new, but I don’t want another directory into root directory, then I have moved the generated code, to my project root, and I forgot mentioned file.

@HDaghash, Thanks! copying .angular-cli.json from an old project to the new worked perfect

Same here. I copied to a new directory using cp -r command where it did not copy .angular-cli.json file which is a hidden file. if your machine is unix/mac then run this command on your source folder to find the .angular-cli.json . after copying to the destination folder it worked like charm. ls -ltr A command should show hidden files.

Got same issue. Cause of this error: Copying project files from old directory to another directory, .angular-cli.json not copied. Solved: By copying .angular-cli.json file from old project directory to new one. Project building successfully.

i found the solution ! 😄 in my case i moved the project to another directory there is a hidden file called .angular-cli show the hidden file in the old project and copy this file and paste it in the new distention . this is solved the issue for me .

I had the same error when I tried to run ng test. The solution was easy. I was located in wrong directory. I had to cd one level deeper, where all my files were located.

It was caused due to missing .angular-cli.json as I created my repo in Linux environment and then was trying to run it in the windows environment by cloning the repo.

Hit the same issue as @narendrasinghrathore @django18, due to missing .angular-cli.json (when copying on macosx finder these .abc files are not visible). Copying the file manually resolved this issue.

Got the same issue today. macOS Sierra (10.12.6) Node v9.4.0 ngCli 1.6.5

Pulled a 3 month old NG app from a repo.

Fix: I created a new App using “ng new foo” and copied the .angular-cli.json file form the new project into the cloned existing one.

I had same problem with @angular/cli: 1.0.0 node: 6.10.3 os: win32 x64

first i tried with command “ng init” and ng build. It didn’t worked. In my case I just restarted the “Visual Studio code” it worked.

SOLUTION: Na pasta do projeto deve conter um arquivo chamado: .angular-cli.json

PS: Caso tenha sido trocado a pasta do projeto para outro local sem ser exibido os arquivos ocultos, este arquivo acaba por não ser copiado junto com o projeto, ocasionando o erro!

I have the same issue after installing @angular/cli 1.0.0-beta.32.3 package but it was caused by the remaining angular-cli 1.0.0-28.3 package in my package.json file! After removing it everything works well. (when exploring my app node_modules directory I found @angular/cli, @angular-cli and angular-cli sub directories - this why I found the solution…)

Hope that helps