Cannot import library with ES Modules
See original GitHub issueI’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:
- Created 7 years ago
- Comments:12 (4 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
import { default as css } from 'sheetify'
works fine for me, though definitely not as nice! kinda wonky to support both thoughhey @knownasilya,
sheetify/transform
only supportsrequire
, and i thinkbabelify
transpilesimport
into a non-statically-analyzablerequire
(by wrapping it in a dynamic function) so that doesn’t help.so possible options:
import sf from 'sheetify'
toconst sf = require('sheetify')
sheetify/transform
, so you could add it beforebabelify
and it’d work.i personally don’t care for ES Modules, but if anyone wants to contribute here i’m keen.