Uncaught SyntaxError: Cannot use import statement outside a module

3,442 views
Skip to first unread message

Inter Net

unread,
Oct 24, 2021, 1:32:21 PM10/24/21
to Chromium Extensions
popup.js is trying to import vendor.js (I use react.js & built with vite.js), but I get this error, I have checked in the HTML type="module" is correctly set on the link element which imports popup.js which then imports the vendor.js. Any idea what I'm missing here? Thanks.
issueext.jpg

wOxxOm

unread,
Oct 25, 2021, 1:03:22 PM10/25/21
to Chromium Extensions, zela...@gmail.com
You probably loaded popup.js somewhere else by mistake e.g. as a content script.

Inside content scripts you can only use the dynamic import(chrome.runtime.getURL('foo.js')) in case foo.js is listed in web_accessible_resources. Also make sure to use getURL as shown here to avoid a recent bug in Chrome with relative paths.

Inter Net

unread,
Oct 25, 2021, 3:24:11 PM10/25/21
to Chromium Extensions, wOxxOm, Inter Net
Ok, I got rid of it because I accidentally had popup.js in my content_scripts but now my newtab.js has the same error and newtab.js is not listed in the content_scripts only in the chrome_url_overrides. I need to say that the code used in newtab.js uses extension api's is this ok or do I need to list them in some permission setting in MV3?

wOxxOm

unread,
Oct 25, 2021, 3:29:44 PM10/25/21
to Chromium Extensions, zela...@gmail.com, wOxxOm
Sounds like newtab.js is loaded without type="module".

Inter Net

unread,
Oct 25, 2021, 6:19:35 PM10/25/21
to Chromium Extensions, wOxxOm, Inter Net
newtab.js is but vendor.js is loded without module is this ok? 
<script type="module" crossorigin src="/assets/newtab.js"></script>
<link rel="modulepreload" href="/assets/vendor.js">

Os

unread,
Oct 26, 2021, 2:52:49 AM10/26/21
to Inter Net, Chromium Extensions
You probably use the chrome://extensions UI to look at the errors in html pages, but this UI shows old errors without any indication they're from the past runs. Click the "clear all" button there, and stop using this UI for debugging html pages altogether, use the built-in devtools debugger on the actual page.

Inter Net

unread,
Oct 26, 2021, 5:45:25 AM10/26/21
to Chromium Extensions, wOxxOm, Chromium Extensions, Inter Net
you are right the error were old errors.
Reply all
Reply to author
Forward
0 new messages