question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

'Chart is not a constructor' when importing as ES6 module

See original GitHub issue

After installing as a npm module (npm install frappe-charts), I’m unable to import a constructor.

Docs says to import like this:

import {Chart} from 'frappe-charts'

…the docs from NPM says to import like this:

import Chart from 'frappe-charts/dist/frappe-charts.min.esm'

Either way it doesn’t work for me.

const chart = new Chart(this.chartWrapper, {...})

results in *.Chart is not a constructor error.

I’m using Webpack 4 and React 16 (but React shouldn’t have anything to do with this issue).

Frappé Charts version: v1.1.0

Any suggestions? Thanks!

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:16 (8 by maintainers)

github_iconTop GitHub Comments

7reactions
andreasvirkuscommented, Oct 25, 2018

You need to import the EcmaScript module straight from the dist folder:

import { Chart } from 'frappe-charts/dist/frappe-charts.esm.js'

cc @deligent-ant @maulerjan @panjizhi

6reactions
himynameisdavecommented, Jun 29, 2020

@scmmishra in the next major version, will there just be a hybrid import which combines ESM/CommonJS (like most NPM packages)? This way users can just do:

// In ESM environments:
import { Chart } from 'frappe-charts';

// In CJS environments:
const { Chart } = require('frappe-charts');

This would be great, so that developers don’t need to worry about digging into the /dist/ folder to find the file that they need.

Read more comments on GitHub >

github_iconTop Results From Across the Web

webpack imported module is not a constructor - Stack Overflow
For me, this error was caused by importing through index files. I had multiple directories with their index.ts files that exported all the...
Read more >
TypeError: "x" is not a constructor - JavaScript - MDN Web Docs
The JavaScript exception "is not a constructor" occurs when there was an attempt to use an object or a variable as a constructor,...
Read more >
Module Methods - webpack
This section covers all methods available in code compiled with webpack. When using webpack to bundle your application, you can pick from a...
Read more >
TypeError: _gauge2.default is not a constructor - Laracasts
I can see ChartJS I just use import Chart from 'chart.js' ; Somehow it auto-discovers which file it needs. ChartJS is a NPM...
Read more >
Using TypeScript or ES6 – amCharts 4 Documentation
import * as am4charts from "@amcharts/amcharts4/charts";. When importing the module, use its npm name @amcharts/amcharts4/... . IMPORTANT. It is ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found