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')
}
}
}
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.
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.