Vue-cli: Build error: Module not found: Error: a dependency to an entry point is not allowed

Created on 9 Mar 2016  路  3Comments  路  Source: vuejs/vue-cli

I am trying to run npm run build on my scaffolding app buit I get this error:

ERROR in ./src/services/auth.js
Module not found: Error: a dependency to an entry point is not allowed
@ ./src/services/auth.js 15:12-30

I can't figure out what problem I have in auth.js file. Here is the code of auth.js:

import Config from '../config/config'
import LocalStorage from './ls'
import { router } from '../main'

export default {

  user: {
    authenticated: false
  },

  login (context, creds, redirect) {
    context.$http.post(Config.api.base_url + '/login', creds).then((response) => {
      LocalStorage.set('jwt-token', response.data.token)

      this.user.authenticated = true
      window.shared_state.authenticated = true

      if (redirect) {
        router.go(redirect)
      }
    }, (err) => {
      context.error = err || true
    })
  },

  signup (context, creds, redirect) {
    context.$http.post(Config.api.base_url, creds).then((response) => {
      LocalStorage.set('jwt-token', response.data.token)

      this.user.authenticated = true
      window.shared_state.authenticated = true

      if (redirect) {
        router.go(redirect)
      }
    }, (err) => {
      context.error = err
    })
  },

  logout () {
    LocalStorage.remove('jwt-token')
    this.user.authenticated = false
    window.shared_state.authenticated = false
  },

  checkAuth () {
    var jwt = LocalStorage.get('jwt-token')
    if (jwt) {
      this.user.authenticated = true
      window.shared_state.authenticated = true
    } else {
      this.user.authenticated = false
      window.shared_state.authenticated = false
    }
  },

  getAuthHeader () {
    return {
      'Authorization': 'Bearer ' + localStorage.getItem('jwt-token')
    }
  }
}

Most helpful comment

Like what the error says... Don't import stuff from main.js because it's the entry point. Split router into another file.

All 3 comments

Like what the error says... Don't import stuff from main.js because it's the entry point. Split router into another file.

Solved it, thanks again for your help!

Also, you should just be able to access the router by changing

router.go(redirect) to this.$router.go(redirect)

without importing the router explicitly.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

eladcandroid picture eladcandroid  路  3Comments

JIANGYUJING1995 picture JIANGYUJING1995  路  3Comments

miyamoto-san picture miyamoto-san  路  3Comments

Akryum picture Akryum  路  3Comments

chasegiunta picture chasegiunta  路  3Comments