0

I'm converting my manifest v2 Chrome extension to v3, and getting the error below when I imported a function from another javascript file, to background.js file;

Uncaught SyntaxError: Cannot use import statement outside a module

background.js

import test_123 from './test.js';

test.js

export function test_123()
{
  alert('test ok');
}

manifest.js

  "background":{
    "service_worker": "background.js"
},

I have too many functions in the test.js file, so it's great if there is any way to import the whole test.js at once using something like require('./test.js')

Can anyone please point me in the right direction to identify the issue and solve it?

Ruwan Liyanage
  • 333
  • 1
  • 13
  • Add "type":"module" to "background" section in manifest.json. – wOxxOm Oct 19 '22 at 07:01
  • @wOxxOm Adding "type":"module" not worked for me. – Ruwan Liyanage Oct 19 '22 at 07:34
  • 1
    Well, since it works normally I guess you either didn't reload the extension or there is a typo or you're looking at the old error, which you can clear by clicking the Clear all button. – wOxxOm Oct 19 '22 at 09:57
  • @wOxxOm Thanks for the tip. I have already tried reloading the extension and reproducing the problem many times. But the result is still the same. Looking for another approach to solve it. – Ruwan Liyanage Oct 19 '22 at 10:54
  • It's the only approach. Another possible mistake would be that you load background.js somewhere else. – wOxxOm Oct 19 '22 at 11:09

0 Answers0