I am experimenting with upgrading my Angular 6 application to Angular 8. My code compiles, but I immediately receive a run-time error "d3.js:8 Uncaught TypeError: Cannot read property 'document' of undefined".
The line failing in d3.js is var d3_document = this.document;
. This leads me to believe that Angular 8 is running d3.js in strict mode. I have the latest version of the d3 node module ("d3": "3.5.17"), and it apparently does not support strict mode; my understanding is "this" is supposed to reference the window object but that does not work in strict mode.
I know Angular 8 now uses dart-sass instead of node-sass, which is supposedly stricter. I did try installing node-sass to use it instead of dart-sass (as recommended by the upgrade documentation), but I am pretty sure this is not sass related.
I will note that some of my other packages need to be updated because they are dependent on Angular 6's packages, but I don't see how this would effect his d3 error.
I have also tried explicitly saying "noImplicitUseStrict": false,
in my tsconfig.json file, but received the same error. I have also tried "noImplicitUseStrict": true,
with no luck.
I have referenced this stack overflow post which addresses the same error: D3.js : Uncaught TypeError: Cannot read property 'document' of undefined, and the referenced solution: https://mcmap.net/q/24681/-how-to-remove-global-quot-use-strict-quot-added-by-babel; but I am having a difficult time applying these to my situation because I am working with an Angular project and unsure if babel applies or how to modify the babel options.
Full Error:
d3.js:8 Uncaught TypeError: Cannot read property 'document' of undefined
at d3.js:8
at Object../node_modules/d3/d3.js (d3.js:9554)
at __webpack_require__ (bootstrap:83)
at Module../dist/core-services/fesm2015/core-services.js (core-services.js:1)
at __webpack_require__ (bootstrap:83)
at Module../src/app/app.component.ts (main-es2015.js:22262)
at __webpack_require__ (bootstrap:83)
at Module../src/app/app.module.ts (app.component.ts:21)
at __webpack_require__ (bootstrap:83)
at Module../src/main.ts (main.ts:1)
(anonymous) @ d3.js:8
./node_modules/d3/d3.js @ d3.js:9554
__webpack_require__ @ bootstrap:83
./dist/core-services/fesm2015/core-services.js @ core-services.js:1
__webpack_require__ @ bootstrap:83
./src/app/app.component.ts @ main-es2015.js:22262
__webpack_require__ @ bootstrap:83
./src/app/app.module.ts @ app.component.ts:21
__webpack_require__ @ bootstrap:83
./src/main.ts @ main.ts:1
__webpack_require__ @ bootstrap:83
0 @ main.ts:17
__webpack_require__ @ bootstrap:83
checkDeferredModules @ bootstrap:45
webpackJsonpCallback @ bootstrap:32
(anonymous) @ main-es2015.js:1
Expected no error. Is there a way to specify that I do not want this node module to run in strict mode?