angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

TypeError: Cannot read property 'config' of null

Open soodvarun opened this issue 9 years ago • 62 comments

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.

soodvarun avatar Feb 16 '17 08:02 soodvarun

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.

ardiadrianadri avatar Feb 16 '17 17:02 ardiadrianadri

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

bougnat12 avatar Feb 20 '17 11:02 bougnat12

I am seeing this issue. Never install angular cli before now so it's not a collision with older version. I've got "@angular/cli": "^1.0.0-rc.0" in package.json.

> ng serve Cannot read property 'config' of null TypeError: Cannot read property 'config' of null at Class.run (/Users/jason/Development/repos/shield/node_modules/@angular/cli/tasks/serve.js:22:63) at check_port_1.checkPort.then.port (/Users/jason/Development/repos/shield/node_modules/@angular/cli/commands/serve.js:103:26) at process._tickCallback (internal/process/next_tick.js:103:7)

I can see that a change has been made to account for the 2 file names as pointed out above:

...
const path = require("path");
const find_up_1 = require("../utilities/find-up");
exports.CLI_CONFIG_FILE_NAME = '.angular-cli.json';
const CLI_CONFIG_FILE_NAME_ALT = 'angular-cli.json';
function getUserHome() {
...

Am I supposed to create that file myself? I can find one here node_modules/@angular/cli/blueprints/ng/files/angular-cli.json but I doubt that's the one it's supposed to be looking for.

jdschmitt avatar Feb 26 '17 18:02 jdschmitt

It also happens if the project is in the home directory (something related to global config file being the same as the project config file)... in my case it was because I used to mount the project in the home of a docker user for building.

dpalita avatar Feb 26 '17 20:02 dpalita

I got this error on an Docker build. I set the HOME env to the same directory as the project root. That's why the configPath and this.globalConfigFilePath() are the same and returned every time with null. 😒

const configPath = this.configFilePath(projectPath);
if (!configPath || configPath === this.globalConfigFilePath()) {
  return null;
}

https://github.com/angular/angular-cli/blob/master/packages/%40angular/cli/models/config.ts#L82

labs-scnm avatar Feb 27 '17 21:02 labs-scnm

Seeing the same issue on Win10. All fine on macOS with same codebase.

simonstewart avatar Feb 28 '17 15:02 simonstewart

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. ¯_(ツ)_/¯

jdschmitt avatar Feb 28 '17 15:02 jdschmitt

@jdschmitt nice! Owe you a beer/coffee when in South Africa.

simonstewart avatar Feb 28 '17 16:02 simonstewart

On my way! ✈️ 🍻

jdschmitt avatar Feb 28 '17 16:02 jdschmitt

Also running into this on Windows. For me build and serve work fine, but any ng generate commands fails with:

TypeError: Cannot read property 'apps' of null

New project created with ng new.

@angular/cli: 1.0.0-rc.0
node: 7.6.0
os: win32 x64
@angular/common: 2.0.0
@angular/compiler: 2.0.0
@angular/core: 2.0.0
@angular/forms: 2.0.0
@angular/http: 2.0.0
@angular/platform-browser: 2.0.0
@angular/platform-browser-dynamic: 2.0.0
@angular/platform-server: 2.0.0
@angular/router: 3.0.0
@angular/upgrade: 2.0.0
@angular/cli: 1.0.0-rc.0

RickStrahl avatar Mar 01 '17 03:03 RickStrahl

same issue for me, when trying to ng serve:


2017-03-07T16:30:34.549+01:00 [APP/PROC/WEB/0] [ERR] Cannot read property 'config' of null
2017-03-07T16:30:34.550+01:00 [APP/PROC/WEB/0] [ERR] at check_port_1.checkPort.then.port (/home/vcap/app/node_modules/@angular/cli/commands/serve.js:103:26)
2017-03-07T16:30:34.550+01:00 [APP/PROC/WEB/0] [ERR] at process._tickCallback (internal/process/next_tick.js:103:7)
2017-03-07T16:30:34.550+01:00 [APP/PROC/WEB/0] [ERR] TypeError: Cannot read property 'config' of null
2017-03-07T16:30:34.550+01:00 [APP/PROC/WEB/0] [ERR] at Class.run (/home/vcap/app/node_modules/@angular/cli/tasks/serve.js:22:63)

removing the '.' from .angular-cli.json didn't solve the problem.

versions:

"node": "7.6.0"
"npm": "4.1.2"
"@angular/cli": "1.0.0-rc.1"

cgebe avatar Mar 07 '17 15:03 cgebe

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.

OneMuppet avatar Mar 07 '17 23:03 OneMuppet

Thank you so much @OneMuppet , it works very good, i had the same probl and i solved it :)

mouna92 avatar Mar 08 '17 13:03 mouna92

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.

filipesilva avatar Mar 13 '17 17:03 filipesilva

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

al-tr avatar Mar 15 '17 22:03 al-tr

I have same problem when trying to build the app on bitbucket pipelines with docker image.

20:35:33.019 [QUIET] [system.out] 
20:35:33.019 [QUIET] [system.out] > [email protected] build /opt/atlassian/pipelines/agent/build/frontend
20:35:33.019 [QUIET] [system.out] > ng build
20:35:33.019 [QUIET] [system.out] 
20:35:34.503 [ERROR] [system.err] Cannot read property 'config' of null
20:35:34.504 [ERROR] [system.err] TypeError: Cannot read property 'config' of null
20:35:34.504 [ERROR] [system.err]     at Class.run (/opt/atlassian/pipelines/agent/build/frontend/node_modules/@angular/cli/tasks/build.js:16:56)
20:35:34.504 [ERROR] [system.err]     at Class.run (/opt/atlassian/pipelines/agent/build/frontend/node_modules/@angular/cli/commands/build.js:143:26)
20:35:34.504 [ERROR] [system.err]     at Class.<anonymous> (/opt/atlassian/pipelines/agent/build/frontend/node_modules/@angular/cli/ember-cli/lib/models/command.js:134:17)
20:35:34.504 [ERROR] [system.err]     at process._tickCallback (internal/process/next_tick.js:103:7)
20:35:34.513 [ERROR] [system.err] 
20:35:34.518 [ERROR] [system.err] npm ERR! Linux 4.9.9-coreos-r1
20:35:34.518 [ERROR] [system.err] npm ERR! argv "/opt/atlassian/pipelines/agent/build/frontend/node/node-v7.6.0-linux-x64/bin/node" "/opt/atlassian/pipelines/agent/build/frontend/node_modules/npm/bin/npm-cli.js" "run" "build"
20:35:34.518 [ERROR] [system.err] npm ERR! node v7.6.0
20:35:34.518 [ERROR] [system.err] npm ERR! npm  v4.1.2
20:35:34.518 [ERROR] [system.err] npm ERR! code ELIFECYCLE
20:35:34.518 [ERROR] [system.err] npm ERR! [email protected] 

Works ok on Win 10 machine locally.

ng --version:

@angular/cli: 1.0.0-rc.0
node: 7.7.3
os: win32 x64
@angular/common: 2.4.5
@angular/compiler: 2.4.5
@angular/core: 2.4.5
@angular/flex-layout: 2.0.0-rc.1
@angular/forms: 2.4.5
@angular/http: 2.4.5
@angular/material: 2.0.0-beta.2
@angular/platform-browser: 2.4.5
@angular/platform-browser-dynamic: 2.4.5
@angular/platform-server: 2.4.5
@angular/router: 3.4.5
@angular/cli: 1.0.0-rc.0
@angular/compiler-cli: 2.4.5

Ludevik avatar Mar 18 '17 21:03 Ludevik

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.

mezoistvan avatar Mar 21 '17 17:03 mezoistvan

Thanks @mezoistvan for hint. Now it works on docker image too :)

Ludevik avatar Mar 22 '17 00:03 Ludevik

Guys you maybe moved your files to another subdirectory.

gtzinos avatar Apr 22 '17 11:04 gtzinos

guys i found the solution ! :D 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 .

HDaghash avatar Apr 26 '17 07:04 HDaghash