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

SyntaxError: import not found: default (js.cookie-2.2.0.min.js) #407

Closed
Darker opened this issue Feb 14, 2018 · 11 comments
Closed

SyntaxError: import not found: default (js.cookie-2.2.0.min.js) #407

Darker opened this issue Feb 14, 2018 · 11 comments
Milestone

Comments

@Darker
Copy link

Darker commented Feb 14, 2018

This is what is stated as valid import syntax in documentation:

import Cookies from 'js-cookie';

But that does produce following error:

SyntaxError: import not found: default

In the following code:

import Cookies from "./lib/js.cookie-2.2.0.min.js";

What is the correct usage?

@PerfectlyNormal
Copy link

I got it working by using import * as Cookies from 'js-cookie'

@FagnerMartinsBrack
Copy link
Member

Hi, thanks for opening an issue on js-cookie.

As stated in the contributing guidelines, in order to take any further action we need a Short, Self Contained, Correct (Compilable), Example that shows a problem with js-cookie.

For support, you can create a question in StackOverflow under the tag js-cookie. The reason why we don't answer support questions on Github is that StackOverflow has a higher relevance in Google results and therefore a solution posted there is more likely to help other people with the same problem 😃 .

Closing for now, but once there's enough information that we can act upon just comment here so that we can reopen it.

If you create a StackOverflow question, please link it here so that we can help here or make it possible for others to find the answer. If you find a solution for your problem, please post it here too so that we can potentially improve the docs.

Don't let this stop you from keep contributing to js-cookie 👍

Thank you!

@Darker
Copy link
Author

Darker commented Feb 19, 2018

Are you kidding me? You need MCVE to reproduce error caused by one line of code? Like if you don't give a damn, just say it.

@FagnerMartinsBrack
Copy link
Member

FagnerMartinsBrack commented Feb 19, 2018

AFAIK browsers don't support ES 6 modules and you need a transpiler to make it work. That means it's not one line of code and there's a lot of assumptions about your code snippets: which transpiler you're using, which version that is, what's your config, etc.

Did anything change? Do browsers support ES 6 modules now without the need for a transpiler? Are you using a transpiler at all?

@FagnerMartinsBrack
Copy link
Member

Ping @Darker.

@Darker
Copy link
Author

Darker commented Feb 20, 2018

Yeah, browsers do support ES6 modules. Not all, and some need you to enable it in dev options first, but it works. See my stackoverflow asnwer: https://stackoverflow.com/a/46415925/607407

Some libraries already support ES6 modules in browser too, such as EventEmitter2:

import EventEmitter from "../lib/event-emitter.js";

Since JSCookie says in the docs that it supports ES6 modules - and it didn't work for me, I reported that as an issue. Fix might be as simple as adding an example import code in documentation.

@FagnerMartinsBrack
Copy link
Member

FagnerMartinsBrack commented Feb 21, 2018

Alright, things have changed then. Does @PerfectlyNormal's answer work? If that's so, can you create a PR to update the docs? Also, how can js-cookie support ES6 modules in a better way conscious of backward compatibility?

@FagnerMartinsBrack
Copy link
Member

can you create a PR to update the docs?

Might be worth a hyperlink to some website that can show the browser support over time.

@Darker
Copy link
Author

Darker commented Feb 21, 2018

I'll test it ASAP and if it works, I'll create PR with docs update.

@FagnerMartinsBrack
Copy link
Member

@Darker any updates on this one?

@FagnerMartinsBrack FagnerMartinsBrack added this to the v2.2.1 milestone Mar 20, 2018
@FagnerMartinsBrack
Copy link
Member

Closing due to the lack of feedback from the OP. Feel free to comment here to open up the discussion again.

I've created #423 to track it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants