Skip to content

Instantly share code, notes, and snippets.

@statico
Last active June 15, 2022 20:23
Embed
What would you like to do?
angular bug: An unhandled exception occurred: Object prototype may only be an Object or null: undefined

we have a project that’s using Node v12 and Angular 7. when i try to build the project with ng build i get An unhandled exception occurred: Object prototype may only be an Object or null: undefined

lots of people on the internet have this problem. there are a few dozen stackoverflow answers, and there are issues on both webpack and typescript the blame each other. it seems to have something to do with circular dependencies, but i’ve run madge --circular --extensions ts ./ which claims to find circular deps but it says none are found. in fact, if i delete all of the page source code other than the entry point, the error still occurs. so this seems to be a bug with the angular build system. i’ve hooked up a debugger and tried to step through the stack but i haven’t found anything useful.

a lot of people say “ok, run ng update.” well, that doesn’t seem to do anything useful. i’ve tried updating to just node v14 and v16, i’ve tried running node-check-updates to update dependencies. warping ahead to Angular 14 causes hundreds of errors in the project.

# no global ng
$ which ng
ng not found
$ npm run ng --version
6.14.16
$ ./node_modules/.bin/ng --version
_ _ ____ _ ___
/ \ _ __ __ _ _ _| | __ _ _ __ / ___| | |_ _|
/ △ \ | '_ \ / _` | | | | |/ _` | '__| | | | | | |
/ ___ \| | | | (_| | |_| | | (_| | | | |___| |___ | |
/_/ \_\_| |_|\__, |\__,_|_|\__,_|_| \____|_____|___|
|___/
Angular CLI: 9.1.5
Node: 12.22.12
OS: darwin x64
Angular: 7.0.3
... animations, common, compiler, core, forms, http
... platform-browser, platform-browser-dynamic, platform-server
... router, service-worker
Ivy Workspace: Yes
Package Version
--------------------------------------------------------------------
@angular-devkit/architect 0.901.15
@angular-devkit/build-angular 0.901.15
@angular-devkit/build-optimizer 0.901.15
@angular-devkit/build-webpack 0.901.15
@angular-devkit/core 9.1.15
@angular-devkit/schematics 9.1.5
@angular/cdk 7.3.4
@angular/cli 9.1.5
@angular/compiler-cli 9.1.6
@angular/language-service 9.1.6
@angular/material 7.3.4
@ngtools/webpack 9.1.15
@nguniversal/express-engine 7.1.1
@nguniversal/module-map-ngfactory-loader 0.0.0
@schematics/angular 9.1.5
@schematics/update 0.901.5
rxjs 6.3.0
typescript 3.8.3
webpack 4.42.0
$ ./node_modules/.bin/ng build
An unhandled exception occurred: Object prototype may only be an Object or null: undefined
See "/private/var/folders/.../angular-errors.log" for further details.
{
"private": true,
"engines": {
"node": "12.x.x"
},
"scripts": {
"ng": "ng",
},
"dependencies": {
"@angular/animations": "7.0.3",
"@angular/cdk": "7.3.4",
"@angular/common": "7.0.3",
"@angular/compiler": "7.0.3",
"@angular/core": "7.0.3",
"@angular/forms": "7.0.3",
"@angular/http": "7.0.3",
"@angular/material": "7.3.4",
"@angular/platform-browser": "7.0.3",
"@angular/platform-browser-dynamic": "7.0.3",
"@angular/platform-server": "7.0.3",
"@angular/router": "7.0.3",
"@angular/service-worker": "7.0.3",
"@material-extended/mde": "2.1.1",
"@nguniversal/express-engine": "7.1.1",
"@nguniversal/module-map-ngfactory-loader": "0.0.0",
"@swimlane/ngx-charts": "10.0.0",
"@types/lodash": "^4.14.175",
"angular-star-rating": "4.0.0-beta.3",
"angularx-social-login": "^1.2.7",
"body-parser": "^1.19.0",
"cookie-parser": "^1.4.5",
"core-js": "2.5.1",
"cross-fetch": "^3.0.4",
"css-star-rating": "1.2.4",
"d3-shape": "1.3.5",
"date-fns": "^2.12.0",
"dotenv": "^8.2.0",
"express": "^4.17.1",
"express-http-proxy": "^1.6.0",
"file-saver": "^2.0.2",
"fontfaceobserver": "2.1.0",
"google-auth-library": "^4.2.6",
"jsonwebtoken": "^8.5.1",
"lodash": "^4.17.21",
"moment": "2.24.0",
"ng-circle-progress": "1.4.0",
"ngx-cookie-service": "^2.1.0",
"ngx-daterangepicker-material": "^2.1.0",
"node-sass": "^4.14",
"rxjs": "6.3.0",
"zone.js": "0.8.26"
},
"devDependencies": {
"@angular-devkit/build-angular": "^0.901.7",
"@angular/cli": "^9.1.5",
"@angular/compiler-cli": "^9.1.6",
"@angular/language-service": "9.1.6",
"@angularclass/hmr": "2.1.3",
"@types/file-saver": "^2.0.1",
"@types/jasmine": "2.5.54",
"@types/jasminewd2": "2.0.3",
"@types/lodash": "^4.14.149",
"@types/node": "^12.12.35",
"@types/url-join": "^4.0.0",
"codelyzer": "^5.1.2",
"hads": "^2.0.2",
"http-proxy-middleware": "^0.19.1",
"husky": "1.3.1",
"jasmine-core": "2.6.4",
"jasmine-spec-reporter": "4.1.1",
"karma": "^5.0.1",
"karma-chrome-launcher": "2.1.1",
"karma-cli": "1.0.1",
"karma-coverage-istanbul-reporter": "1.3.0",
"karma-jasmine": "1.1.0",
"karma-jasmine-html-reporter": "0.2.2",
"ng-inline-svg": "8.3.0",
"ngx-take-until-destroy": "5.4.0",
"protractor": "^5.4.3",
"puppeteer": "1.13.0",
"stylelint": "^13.3.2",
"stylelint-config-recommended-scss": "3.2.0",
"stylelint-config-standard": "18.2.0",
"stylelint-scss": "3.3.0",
"ts-loader": "5.2.0",
"ts-node": "3.2.2",
"tslint": "5.7.0",
"typescript": "3.8.3",
"webpack-cli": "^3.3.11"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment