Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ES6 Modules In Google Chrome Extension Development (unexpected token)

Is it possible to use ES6 modules in Google Chrome Extension Development?

I get 'unexpected token export' or 'unexpected token import'.

like image 308
tobiasmueller Avatar asked Apr 22 '16 14:04

tobiasmueller


People also ask

Can I use ES6 on Chrome extension?

JavaScript in ECMAScript 6 supports modules which you may now use in Google Chrome since version 61.

How do I fix Unexpected token export?

To solve the "Uncaught SyntaxError Unexpected token 'export'" error, set the type of your <script /> tags to module , e.g. <script type="module" src="index. js"></script> . The type="module" attribute is supported in all modern browsers and allows us to use the ES6 modules syntax.


1 Answers

Well sort of, you can see here in the compatibility table for chrome that not everything is available. Chrome is good about adding ES6 features with each release but currently import is not supported.

http://kangax.github.io/compat-table/es6/

Now that said, you can use all ES6 features if you use a compiler like babel

https://babeljs.io/

Check out this answer for more info, note it is dated: Is it possible to use ES6 in a Chrome Extension?

like image 120
omarjmh Avatar answered Oct 01 '22 01:10

omarjmh