Can't import npm package using es6 module
See original GitHub issueHi,
sorry for a stupid question, but I just can’t seem to import the Cookies object in my project no matter what I try.
Here is what I tried:
import 'js-cookie'
and
import Cookie from 'js-cookie'
window.Cookie = Cookie
None produce any Cookie names object in the window, or local context. I can import any other packages just fine, but somehow not this one.
Any ideas why that might be?
Issue Analytics
- State:
- Created 7 years ago
- Comments:16 (7 by maintainers)
Top Results From Across the Web
Cannot Import My NPM Package With ES6 Import/Export Syntax
I want it to work WITHOUT webpack. This is why this is partially solved. javascript · npm · ecmascript-6 · module · importerror....
Read more >Cannot import modules installed with NPM - Sololearn
I'm using ES6 import keyword, I have tried this with a various of different packages, but it just doesn't work, for example, I...
Read more >ECMAScript modules | Node.js v19.3.0 Documentation
ECMAScript modules are the official standard format to package JavaScript code for reuse. Modules are defined using a variety of import and export...
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 >can not use import statement outside a module - YouTube
JS - JavaScript. syntaxerror - can not use import statement outside a module | es6 vs commonjs modules in nodejs.
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 Free
Top 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

The es6 module spec doesn’t have anything similar to the
module.exports = obj, there’s only default and named exports.Fortunately, you can still fake it by doing:
In this case, all the variable and functions from the exported object will be ‘transferred’ over the the
Cookiesobject.Note: If you are using TypeScript, use the
--allowSyntheticDefaultImportsflag.So no code changes needed, adding this usage to the docs however would be nice 😃
I just installed version
2.1.4and the following works for me with webpack :