Cannot import examples: "SyntaxError: Cannot use import statement outside a module"

I’m unable to use examples from three.js as described here. Importing from three like

import { Mesh } from 'three'

works fine, however e.g.

import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader'

always returns

Uncaught C:\Users\[...]\Documents\JavaScript\electron-setup\node_modules\three\examples\jsm\loaders\GLTFLoader.js:9
import {

SyntaxError: Cannot use import statement outside a module

How do I solve this?

I’m trying to make it run on electron. I’m using the boilerplate code from electron-boilerplate.


1 Like

Turns out it was a bad boilerplate. Switching to electron-forge solved the problem.

1 Like

I suggest you delete your post at stackoverflow. Or provide an answer as well like here.