Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

export 'default' (imported as 'Three') was not found in 'three'

Overview In main.js, add

import Three from 'three'

Vue.use(Three)

Start dev server with npm run dev. Expected behavior The Vue project should load without errors. Actual behavior The dev server gives this warning:

warning  in ./src/main.js
    7:8-14 "export 'default' (imported as 'Three') was not found in 'three'

And the browser's js console displays the error:

Uncaught TypeError: Cannot read property 'installed' of undefined
at Function.Vue.use (eval at <anonymous> (app.js:723), <anonymous>:3443:15)
at eval (eval at <anonymous> (app.js:778), <anonymous>:14:45)
at Object.<anonymous> (app.js:778)
at __webpack_require__ (app.js:660)
at fn (app.js:84)
at Object.<anonymous> (app.js:964)
at __webpack_require__ (app.js:660)
at app.js:709
at app.js:712
like image 208
L.chaoxue Avatar asked Aug 29 '17 11:08

L.chaoxue


People also ask

Why export default is not working?

The "export default was not found" error occurs when we try to import as default from a module that doesn't have a default export. To solve the error, make sure the module has a named export and wrap the import in curly braces, e.g. import {myFunction} from './myModule' .

Can you export default multiple?

Every module can have two different types of export, named export and default export. You can have multiple named exports per module but only one default export.

Can't import the named export Me imported as me ') from default exporting module only default export is available?

Solution: You Just need to Downgrade the Framer motion version to “4.1. 17” in your package. json file and then run npm install Now, Your error must be solved.

What is export default in JavaScript?

The export statement is used when creating JavaScript modules to export objects, functions, variables from the module so they can be used by other programs with the help of the import statements.


2 Answers

It's happening because there are no default export made in the ThreeJS library, so you can import everything like this:

import * as Three from 'three';

Also you don't need the Vue.use since this is not VueJS Plugin.

Since there are no default export, you are able to import specific part from ThreeJS, like this:

import { Scene } from 'three';
like image 191
Belmin Bedak Avatar answered Sep 22 '22 12:09

Belmin Bedak


You can't use Three.js directly, you need a Vue wrapper around it, you can find one here

If you do want to use it directly, you have several options:

  1. Import it in every file and use it:

    import Three from 'three'
    Three.doSomething
    
  2. Import it in the main file and put it on the window object:

    window.Three = require('Three');
    
  3. Add it to the Vue instance (preferred way):

     import Three from 'three';
     Object.definePrototype(Vue.prototype, '$three', { value: Three});
    

and then you can refer to it like this: this.$three

like image 23
Tomer Avatar answered Sep 20 '22 12:09

Tomer