Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ES6 (ES2015) module imports not working #1

Closed
ranaalisaeed opened this issue May 22, 2021 · 3 comments
Closed

ES6 (ES2015) module imports not working #1

ranaalisaeed opened this issue May 22, 2021 · 3 comments
Assignees
Labels
enhancement New feature or request

Comments

@ranaalisaeed
Copy link
Owner

ranaalisaeed commented May 22, 2021

D3 library has to be imported using:
import * as d3Fetch from 'd3-fetch'

Error:

export 'default' (imported as 'd3Fetch') was not found in 'd3-fetch' (possible exports: blob, buffer, csv, dsv, html, image, json, svg, text, tsv, xml)

what is needed to convert to
import d3Fetch from 'd3-fetch'

@ranaalisaeed
Copy link
Owner Author

Another way to import that works is:

import { csv } from 'd3-fetch'
csv('/data/output.csv').then(function(data) { 
	console.log('csv', data)
})

@ranaalisaeed ranaalisaeed self-assigned this May 22, 2021
@ranaalisaeed ranaalisaeed added the enhancement New feature or request label May 22, 2021
@ranaalisaeed
Copy link
Owner Author

Two options in tsconfig.json deal with default imports:

"allowSyntheticDefaultImports": true,     /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
"esModuleInterop": true                   /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */

@ranaalisaeed
Copy link
Owner Author

Following are the ways to deal with default imports

  1. import * as d3Fetch from 'd3-fetch' --> all exports in d3-fetch will be made available under d3Fetch
  2. import { csv } from 'd3-fetch --> only export function csv(){} will be imported and can be used directly without any prefix
  3. enable allowSyntheticDefaultImports and esModuleInterop flags in tsconfig.json and then import d3Fetch from 'd3-fetch' will work.

@ranaalisaeed ranaalisaeed moved this from To do to Done in Incremental build project May 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Development

No branches or pull requests

1 participant