Q:

Use module scripts in web worker

Web worker scripts are loaded when a Worker is instantiated but how can I use a script that is a module so I don't get an error? ( assume the browser supports modules). 
const worker = new Worker('my-worker.js')

In my-worker.js
import {foo} from 'foo.js'
console.log(foo)

A:

Use the type option:
const worker = new Worker('my-worker.js', {type:"module"});

type: A DOMString specifying the type of worker to create.  The value can be classic or module.  If not specified, the default used is classic.