Cannot import example files in Nuxt.js / Vue.js

I followed the official document, and "import * as THREE from ‘three’ " works fine, but not the example file. Is there anything that I am missing?

Error

SyntaxError
Unexpected token {

Source Code

<template>
</template>
<script>
import * as THREE from 'three'
import { OrbitControls } from "three/examples/jsm/controls/OrbitControls.js"

export default{
}
</script>

Versions

nuxt 2.0.0
three 0.106.2

Are you sure the syntax error comes from the imports? Does it work if you remove your export default statement?

It doesn’t work even if I remove export default statement

Can you please demonstrate the issue with a live example? Otherwise consider to share your code as a github repository.

I import three just fine in vue, just as you have it. That does not necessarily show an issue with import. I would try and remove the import and see if that compiles. Or import another lib.

Templates i thought needed a root element.

1 Like

Thanks everyone for your help, I uploaded my code to github↓

Until this part compiles fine import * as THREE from 'three'

I’ve had a look at your project but unfortunately I’m not familiar with Vue and Nuxt. This seems to be no three.js issue so a post at stackoverflow might be more promising.