Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Webpack Imported Module is not a function

Tags:

webpack

vue.js

I have a repository (in a MenuRepository.js file) that has an index() method, when I try to call that method from my mounted() function in my Vue instance, I get the following error

enter image description here

This has been working before, So I can't imagine what happened.. This is the code of my Vue instance.

class MenuRepository {
  async index () {
    const result = await Nova.request().get('/')
    return result.data
  }
}

export default MenuRepository

And this is the Vue file

import MenuRepository from '../repositories/MenuRepository'

export default {
  async mounted () {
    try {
      const menus = await MenuRepository.index()
    } catch (err) {
      console.error(err)
    }
  }
}
like image 530
Miguel Stevens Avatar asked Mar 11 '19 09:03

Miguel Stevens


People also ask

How import works in webpack?

The imports loader allows you to use modules that depend on specific global variables. This is useful for third-party modules that rely on global variables like $ or this being the window object. The imports loader can add the necessary require('whatever') calls, so those modules work with webpack.

Does webpack use CommonJS?

Webpack supports the following module types natively: ECMAScript modules. CommonJS modules.


1 Answers

Solution

The issue was that it wasn't being instantiated.

Use

export default new MenuRepository()

Instead of

export default MenuRepository
like image 114
Miguel Stevens Avatar answered Sep 20 '22 12:09

Miguel Stevens