Django sending syntax errors on ES syntax of imported JS file

23 views
Skip to first unread message

lakeshow

unread,
Mar 2, 2018, 1:32:45 AM3/2/18
to Django users
I'm attempting to use the script of a third party JS library:  

{% block javascript %}
    <script src="{% static 'js/typed/typed.js' %}"></script>  
    ...
{% endblock javascript %}
Doing so will return an error: `Uncaught SyntaxError: Enexpected token {`  
And this error refers to line 1 of 'typed.js', more specifically, this line of JS code:  `import { initializer } from './initializer.js';`

What seems to be the problem? I have no trouble including the scripts of any other JS code. The only difference I see between this instance and my working JS files is that this library I'm attempting to use uses syntax particular to ES(?)  

Here is the specific library in question: https://github.com/mattboldt/typed.js/  

It's a relatively well known library so I don't think the code is a problem either.  




Jani Tiainen

unread,
Mar 2, 2018, 2:30:46 AM3/2/18
to django...@googlegroups.com
Hi, looks like you're using original typed library which is written in ES and it's not very well supported among the browsers. You should pick transpiled version from lib-directory, that should work with all browsers without problems.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/044cef5d-7a71-4d62-8ff2-d55f3e13143c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Jani Tiainen

- Well planned is half done, and a half done has been sufficient before...

Jason

unread,
Mar 2, 2018, 6:29:33 AM3/2/18
to Django users
Jani Tiainen, Your assertion that ES is not very well supported is incorrect.  Most of ES6 is in fact highly supported across browsers except for certain specifications that are still being worked on regarding implementation details.  For reference, look at http://kangax.github.io/compat-table/es6/. It all depends on your target audience, but using babel to transpile by default is a good practice.

As to the original issue, the problem is OP is using a non-compatible browser for imports, as you can see at https://caniuse.com/#feat=es6-module  Firefox and IE are the big names that have  no native support and will require a transpiled version to work.

TL;dr front end can be a mess, OP got caught in it and there are ways around it.

Jani Tiainen

unread,
Mar 2, 2018, 12:05:23 PM3/2/18
to django...@googlegroups.com
Well that was my intention to mean that this particular feature (import statement) seems to lack support for somewhat popular browsers.

Also I think caniuse lags a bit since if I'm not mistaken latest FF supports import.

And in any case JS errors are not Django related.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
Reply all
Reply to author
Forward
0 new messages