未找到/导入Vue.js Webpack模块

时间:2018-06-18 08:14:00

标签: webpack vue.js

我写了一个与vue路由器一起使用的AuthService,但是我无法将AuthService导入到我的路由器文件中,我收到以下错误:

_auth_AuthService__WEBPACK_IMPORTED_MODULE_5__ is not a constructor

我这样导入:import AuthService from '../auth/AuthService' 像这样导出:export default class AuthService {...}

在App.Vue文件中我使用AuthService没有问题,其中导入服务如下:

import AuthService from './auth/AuthService'
const auth = new AuthService()
const { login, logout, authenticated, authNotifier } = auth

也许是某种设置问题?

1 个答案:

答案 0 :(得分:0)

我遇到了同样的问题。我的问题是位于AuthService中。我通过在构造函数中初始化auth解决了这个问题。如,

class AuthService {

  constructor() {
    this.login = this.login.bind(this)
    this.setSession = this.setSession.bind(this)
    this.logout = this.logout.bind(this)
    this.isAuthenticated = this.isAuthenticated.bind(this)
    this.authenticated = this.isAuthenticated()
    this.authNotifier = new EventEmitter()
    this.auth0 = new auth0.WebAuth({
      domain: AUTH_CONFIG.domain,
      clientID: AUTH_CONFIG.clientId,
      redirectUri: AUTH_CONFIG.callbackUrl,
      audience: `https://${AUTH_CONFIG.domain}/userinfo`,
      responseType: 'token id_token',
      scope: 'openid'
    })
  }
}