Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
547 views
in Technique[技术] by (71.8m points)

d3.js - d3v5 Angular 8 production mode - ERROR TypeError: (void 0) is not a function

D3v5 functions work fine in development mode but throwing run time errors in production mode

ERROR TypeError: (void 0) is not a function

Type script code

import { Component } from '@angular/core';
import {timeFormat} from 'd3-time-format';
...
export class AppComponent {

  constructor(){
    var formatTime = timeFormat("%B %d, %Y");
   console.log('Time parser :: ', formatTime(new Date))
  }
}

Package.json

  "dependencies": {
    "@angular/animations": "~8.1.1",
    "@angular/common": "~8.1.1",
    "@angular/compiler": "~8.1.1",
    "@angular/core": "~8.1.1",
    "@angular/forms": "~8.1.1",
    "@angular/platform-browser": "~8.1.1",
    "@angular/platform-browser-dynamic": "~8.1.1",
    "@angular/router": "~8.1.1",
    "@types/d3": "^5.7.2",
    "d3": "^5.13.1",
    "rxjs": "~6.4.0",
    "tslib": "^1.9.0",
    "zone.js": "~0.9.1"
  },

tsconfig.json - Also tried updating the target as per Error in d3.js after upgrading to Angular 8

{
  "compileOnSave": false,
  "compilerOptions": {
    "baseUrl": "./",
    "outDir": "./dist/out-tsc",
    "sourceMap": true,
    "declaration": false,
    "downlevelIteration": true,
    "experimentalDecorators": true,
    "module": "esnext",
    "moduleResolution": "node",
    "importHelpers": true,
    **"target": "es5",**
    "typeRoots": [
      "node_modules/@types"
    ],
    "lib": ..
  },
  "angularCompilerOptions": ..
}

Any suggestion or leads will be much appreciated.

Thanks

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

For anyone encountering similar issue I was able to make it work by bumping d3 and angular to the below versions

 "dependencies": {
    "@angular/animations": "~8.2.14",
    "@angular/common": "~8.2.14",
    "@angular/compiler": "~8.2.14",
    "@angular/core": "~8.2.14",
    "@angular/forms": "~8.2.14",
    "@angular/platform-browser": "~8.2.14",
    "@angular/platform-browser-dynamic": "~8.2.14",
    "@angular/router": "~8.2.14",
    "@types/d3": "^5.7.2",
    "d3": "^5.14.0",
    "rxjs": "~6.4.0",
    "tslib": "^1.10.0",
    "zone.js": "~0.9.1"
  },

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...