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

Production build fails with message "Cannot read property 'input' of null"

Open maylukas opened this issue 9 years ago • 34 comments

OS?

node:6.9.4 docker container

Versions.

[email protected] [email protected]

Repro steps.

After an upgrade to 1.0.0-beta.26 from 1.0.0-beta.24 the app fails to build. Build always starts with a clean docker container in which the following steps are run: FROM node:6.9.4 WORKDIR /root/ RUN npm install [email protected] -g

COPY package.json ./package.json RUN npm install

COPY src ./src/ COPY e2e ./e2e/ COPY angular-cli.json ./angular-cli.json COPY protractor.conf.js ./protractor.conf.js COPY karma.conf.js ./karma.conf.js COPY tslint.json ./tslint.json

RUN ng build --prod

Prod build works when running on the development machine with Windows 7

The log given by the failure.

Cannot read property 'input' of null TypeError: Cannot read property 'input' of null at ObjectSchemaTreeNode._set (/root/node_modules/@ngtools/json-schema/src/sc hema-tree.js:347:132) at new ObjectSchemaTreeNode (/root/node_modules/@ngtools/json-schema/src/sch ema-tree.js:331:14) at OneOfSchemaTreeNode.NonLeafSchemaTreeNode._createChildProperty (/root/nod e_modules/@ngtools/json-schema/src/schema-tree.js:244:24) at /root/node_modules/@ngtools/json-schema/src/schema-tree.js:260:26 at Array.map (native) at new OneOfSchemaTreeNode (/root/node_modules/@ngtools/json-schema/src/sche ma-tree.js:259:48) at ArraySchemaTreeNode.NonLeafSchemaTreeNode._createChildProperty (/root/nod e_modules/@ngtools/json-schema/src/schema-tree.js:244:24) at ArraySchemaTreeNode._set (/root/node_modules/@ngtools/json-schema/src/sch ema-tree.js:434:39) at new ArraySchemaTreeNode (/root/node_modules/@ngtools/json-schema/src/sche ma-tree.js:414:14) at ObjectSchemaTreeNode.NonLeafSchemaTreeNode._createChildProperty (/root/no de_modules/@ngtools/json-schema/src/schema-tree.js:244:24) at ObjectSchemaTreeNode._set (/root/node_modules/@ngtools/json-schema/src/sc hema-tree.js:347:47) at new ObjectSchemaTreeNode (/root/node_modules/@ngtools/json-schema/src/sch ema-tree.js:331:14) at ArraySchemaTreeNode.NonLeafSchemaTreeNode._createChildProperty (/root/nod e_modules/@ngtools/json-schema/src/schema-tree.js:244:24) at ArraySchemaTreeNode._set (/root/node_modules/@ngtools/json-schema/src/sch ema-tree.js:434:39) at new ArraySchemaTreeNode (/root/node_modules/@ngtools/json-schema/src/sche ma-tree.js:414:14) at RootSchemaTreeNode.NonLeafSchemaTreeNode._createChildProperty (/root/node _modules/@ngtools/json-schema/src/schema-tree.js:244:24) at RootSchemaTreeNode.ObjectSchemaTreeNode._set (/root/node_modules/@ngtools /json-schema/src/schema-tree.js:347:47) at RootSchemaTreeNode.ObjectSchemaTreeNode [as constructor] (/root/node_modu les/@ngtools/json-schema/src/schema-tree.js:331:14) at new RootSchemaTreeNode (/root/node_modules/@ngtools/json-schema/src/schem a-tree.js:478:16) at GeneratedSchemaClass.SchemaClassBase (/root/node_modules/@ngtools/json-sc hema/src/schema-class-factory.js:66:29) at new GeneratedSchemaClass (/root/node_modules/@ngtools/json-schema/src/sch ema-class-factory.js:165:20) at new CliConfig (/root/node_modules/angular-cli/models/config/config.js:24: 24) at Function.CliConfig.fromConfigPath (/root/node_modules/angular-cli/models/ config/config.js:99:16) at Function.CliConfig.fromProject (/root/node_modules/angular-cli/models/con fig.js:63:44) at Class.run (/root/node_modules/angular-cli/tasks/build-webpack.js:14:73) at Class.buildRun (/root/node_modules/angular-cli/commands/build.run.js:39:2 2) at Class.run (/root/node_modules/angular-cli/commands/build.js:38:47) at Class. (/root/node_modules/angular-cli/ember-cli/lib/models/co mmand.js:147:17) at process._tickCallback (internal/process/next_tick.js:103:7) The command '/bin/sh -c ng build --prod' returned a non-zero code: 1

Mention any other details that might be useful.

angular-cli.json

{ "project": { "version": "1.0.0-alpha.2", "name": "core-ui" }, "apps": [ { "root": "src", "outDir": "dist", "genDir": "gen", "assets": ["assets"], "index": "index.html", "main": "main.ts", "test": "test.ts", "tsconfig": "tsconfig.json", "prefix": "app", "mobile": false, "styles": [ "scss/style.scss" ], "scripts": [ "../node_modules/pace-js/pace.min.js", "../node_modules/chart.js/dist/Chart.bundle.min.js", "../node_modules/chart.js/dist/Chart.min.js" ], "environments": { "source": "environments/environment.ts", "dev": "environments/environment.ts", "prod": "environments/environment.prod.ts" } } ], "e2e": { "protractor": { "config": "./protractor.conf.js" } }, "test": { "karma": { "config": "./karma.conf.js" } }, "defaults": { "styleExt": "scss", "prefixInterfaces": false } }

maylukas avatar Jan 24 '17 15:01 maylukas

I don't know the cause of the issue as i did not invest enough time to understand the parsing of the configuration but if I change Line 347 in @ngtools/json-schema/src/schema-tree.js from this._children[name_1] = this._createChildProperty(name_1, value ? value[name_1] : null, forward ? forward.children[name_1] : null, propertySchema); to this: this._children[name_1] = this._createChildProperty(name_1, value ? value[name_1] : null, forward && forward.children ? forward.children[name_1] : null, propertySchema);

it works again

maylukas avatar Jan 24 '17 16:01 maylukas

Can you show me your angular-cli.json? Maybe you have a property there that's not supported anymore or something.

filipesilva avatar Jan 24 '17 18:01 filipesilva

I actually provided it in the issue description under "Mention any other details that might be useful.".

maylukas avatar Jan 25 '17 07:01 maylukas

I'm having the same exact problem.

hoatle avatar Jan 26 '17 14:01 hoatle

I guess this is the root cause (related to Docker, not sure about other cases).

When I have angular app under $HOME path, I got the same exact problem.

When I move the angular app out of $HOME path, it works as expected, no error.

hoatle avatar Jan 29 '17 06:01 hoatle

@maylukas this configuration should work with your project:

FROM node:6.9.4

RUN mkdir -p /opt/app
WORKDIR /opt/app
RUN npm install [email protected] -g

COPY package.json ./package.json
RUN npm install

COPY src ./src/
COPY e2e ./e2e/
COPY angular-cli.json ./angular-cli.json
COPY protractor.conf.js ./protractor.conf.js
COPY karma.conf.js ./karma.conf.js
COPY tslint.json ./tslint.json

RUN ng build --prod

hoatle avatar Jan 29 '17 06:01 hoatle

@hoatle Thanks for taking the time to share this, can't say how happy I am to have this working finally! :)

alexweber avatar Feb 01 '17 22:02 alexweber

Today I've updated angular-cli and now I get this same error.

ghost avatar Feb 02 '17 01:02 ghost

@giertych97 That's unrelated to this particular issue. See here for a fix for the new release breaking builds: https://github.com/angular/angular-cli/issues/4326#issuecomment-276819350

alexweber avatar Feb 02 '17 01:02 alexweber

@filipesilva I have had the same issue in my production builds to Heroku since Beta 25 (Beta 24 & earlier worked great, however I just updated to Beta 28 & can confirm the issue still exists).

2017-02-02T13:23:29.383781+00:00 app[web.1]: TypeError: Cannot read property 'input' of null
2017-02-02T13:23:29.383783+00:00 app[web.1]:     at new ObjectSchemaTreeNode (/app/node_modules/@ngtools/json-schema/src/schema-tree.js:331:14)

I believe it may have something to do with the JSON Schema feature added in Beta 25:

@ngtools/json-schema: Introduce a separate package for JSON schema. (#3927) (74f7cdd)

This does not happen when I kick off a build in my local environment npm start - all things are working as expected on localhost:4300. It is only when I deploy & Heroku kicks off the npm start that it will fail on the ng build (it breaks before it is able to create a /dist folder)

This type of error message is similar to the ones seen when an npm package is missing a Types declaration file - unfortunately, one does not exist for the JSON Schema package. Maybe this is related to that? Another hunch is that it may be related to Linux.

I made a comment on this in another thread a while back but didn't follow up until just now - here's a link for additional context

Hopefully this provides some additional insight to the bug

dustintheweb avatar Feb 02 '17 14:02 dustintheweb

Maybe this will help. I accidentally called ng init in Нome directory, after call the ng in any other directory caused the error (even when call ng --version). After deleting ng files from the home directory. ng runs without errors

dlimkin avatar Feb 02 '17 21:02 dlimkin

@dustintheweb did you find any solution?

juanmcampos avatar Feb 02 '17 22:02 juanmcampos

@dlimkin Thank you, it solved my problem! It seems like I had some old Angular files in the root of my home directory causing all Angular projects in there with later Angular-cli versions to fail. So by deleting all files and folders that doesn't belong to the home directory, it solves the problems and the errors disappears.

Mattee avatar Feb 03 '17 08:02 Mattee

@dlimkin solution works. Removing all the ng files from the home directory solved it. Thanks.

robertorosas avatar Feb 03 '17 16:02 robertorosas

For me, this issue is weirdly specific to a new build - only in my live production environment (Heroku / Ubuntu). Everything gets built fresh from the package.json on deploy (no old files), so no possibilities of similar ng gremlins for me in that regard.

Can anyone with a similar live production env also confirm that this is an issue?

dustintheweb avatar Feb 03 '17 17:02 dustintheweb

@dustintheweb I'm getting it too and only when building in Docker

alexweber avatar Feb 03 '17 17:02 alexweber

anyone using Docker, I recommend using this Docker image to get started https://hub.docker.com/r/teracy/angular-cli/tags/

or you can use this seed project https://github.com/teracyhq/angular-boilerplate that I'm working on

I do not have any issues so far with these 2 projects.

hoatle avatar Feb 04 '17 04:02 hoatle

@hoatle Thanks for the tip! Unfortunately my project's openshift s2i environment doesn't allow me to use docker images (even though OC itself supports it), we're currently using: https://hub.docker.com/r/ryanj/centos7-s2i-nodejs/ which is itself pretty out of date, sigh. :(

alexweber avatar Feb 04 '17 14:02 alexweber

OSX 10.12.3 NPM 4.2.0 [ISSUE] Encounter the same issue when I updated angular-cli and ran $ng new appname. App wouldn't build.

[RESOLVED]

  1. ran npm uninstall angular-cli -g
  2. ran npm uninstall angular-cli --save
  3. Confirmed angular-cli was not in /usr/local/lib/node_modules
  4. Confirmed angular-cli was not in /Users/username/node_modules
  5. Confirmed there was no package.json or angular package files in /Users/username/
  6. Reinstall angular cli npm install angular-cli -g
  7. Ran ng -v output angular-cli: 1.0.0-beta.28.3 node: 7.3.0 os: darwin x64
  8. Successfully created new project with ng new project

I think my main issue was having a package.json in my /Users/username/

BodieLeonard avatar Feb 04 '17 14:02 BodieLeonard

To add to what others have mentioned, on Ubuntu if you have an angular-cli.json file in your home directory, it seems to get read (and maybe merged) whenever running ng commands in any folder. If you have a project directly in your home directory the json file seems to get read twice, which screws up parsing if you specify styles property.

Simplest way to see this behavior is to create an empty angular-cli.json in your home directoy, and then run the angular-cli tests, many of which will fail:

touch ~/angular-cli.json 

git clone https://github.com/angular/angular-cli.git
cd angular-cli
npm install && npm test

@filipesilva is this expected behaviour?

UPDATE

In the config design doc I see that it was proposed to use $HOME/.angular-cli.json as a fallback global config, but in implementation $HOME/angular-cli.json (no dot prefix) is used as a fallback and there is no check in case the fallback path == the project path.

This is a serious limitation for anyone who wants to deploy with heroku/dokku/etc. where the app is always installed directly to the $HOME directory.

Ways I think this could be resolved:

  • the dot prefix should be used to avoid this collision, and/or
  • the fallback config should only be read for global ng commands (like new), and/or
  • there should be a check to ensure the same file isn't used as a fallback for itself

mikejpeters avatar Feb 06 '17 22:02 mikejpeters