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.

Cannot import library with ES Modules

See original GitHub issue

I’m using “babel-preset-es2015”: “^6.9.0” with “babelify”: “^7.3.0”, and import sf from 'sheetify'; doesn’t work (5.0.3 of sheetify). I get:

Uncaught TypeError: (0 , _sheetify2.default) is not a function
1.on-load @ google-map.js:4
s @ _prelude.js:1
(anonymous function) @ _prelude.js:12
../components/google-map @ index.js:3
s @ _prelude.js:1
e @ _prelude.js:1
(anonymous function) @ _prelude.js:1

Issue Analytics

  • State:open
  • Created 7 years ago
  • Comments:12 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
tjcommented, Jul 16, 2016

import { default as css } from 'sheetify' works fine for me, though definitely not as nice! kinda wonky to support both though

2reactions
ahdinosaurcommented, Jul 1, 2016

hey @knownasilya,

sheetify/transform only supports require, and i think babelify transpiles import into a non-statically-analyzable require (by wrapping it in a dynamic function) so that doesn’t help.

so possible options:

  • change import sf from 'sheetify' to const sf = require('sheetify')
  • add support for ES Modules to sheetify/transform, so you could add it before babelify and it’d work.

i personally don’t care for ES Modules, but if anyone wants to contribute here i’m keen.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Use ES Modules in Node.js & Fix "cannot use import ...
This article explains ECMAScript modules in Node.js, and how to use import and export modules in Node.js. Fix cannot use import statement outside...
Read more >
cant get ES modules to work with import or require
You need to use a dynamic import. It's worth mentioning that ES modules cannot be imported using the require() function of cjs ....
Read more >
Cannot import and use my package: Vulcheck #3904 - GitHub
Your library (or NPM package, whatever you want to call it) seems to be using ES modules (ESM) rather than CommonJS (CJS), ES...
Read more >
Difference between node.js require and ES6 import and export
ES6 Import & Export: These statements are used to refer to an ES module. Other file types can't be imported with these statements....
Read more >
Using ES modules with CommonJS modules in Node.js
You cannot use require to load an ES module. Error [ERR_REQUIRE_ESM]: Must use import to load ES Module. So, what does work? An...
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