New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

$axios is not available #56

Closed
NeOMakinG opened this Issue Feb 5, 2018 · 22 comments

Comments

Projects
8 participants
@NeOMakinG

NeOMakinG commented Feb 5, 2018

Hello guys,

Someone faced this error on nuxt ? I've added the 2 modules to nuxt.config.js and the auth module return me this error with !this.app.$axios...

Thanks for your response..

NeOMakinG

This question is available on Nuxt.js community (#c43)
@fanckush

This comment has been minimized.

fanckush commented Feb 5, 2018

Im not sure why this is happening but did you add axios to the modules before auth? like so:

modules: [
'@nuxtjs/axios',
'@nuxtjs/auth'
],

@NeOMakinG

This comment has been minimized.

NeOMakinG commented Feb 5, 2018

Yes exactly did like that !

@fanckush

This comment has been minimized.

fanckush commented Feb 5, 2018

Thats about all i can help. How about trying a fresh empty nuxt project and install auth immediately after and see if you get a problem, this should narrow down the cause. if it does work maybe then maybe in your current project something is wrong in the nuxt config or code you wrote

Is the error from code you've written or is it internal?

@NeOMakinG

This comment has been minimized.

NeOMakinG commented Feb 5, 2018

It's an error from the auth-module, in auth.class, because Axios is probably not loaded in the app, but why...

Trying to install a fresh nuxt install to check, thanks for your help anyway ;)

@NeOMakinG

This comment has been minimized.

NeOMakinG commented Feb 5, 2018

Well, tried this on a fresh new app, and It's doing the same thing!

@fanckush

This comment has been minimized.

fanckush commented Feb 5, 2018

What do you have in package.json in dependencies:{}:

@NeOMakinG

This comment has been minimized.

NeOMakinG commented Feb 5, 2018

"dependencies": { "@nuxtjs/auth": "^4.0.0-rc.3", "@nuxtjs/axios": "^5.0.0", "nuxt": "^1.0.0" }

That's the fresh new app

@fanckush

This comment has been minimized.

fanckush commented Feb 5, 2018

ok everything seems fine! Are you using a nuxt template or you are doing it from scratch

In my case i am using the starter template from https://github.com/nuxt-community/starter-template and it works

@NeOMakinG

This comment has been minimized.

NeOMakinG commented Feb 5, 2018

Using the starter template on my main app, not working too ^^

@fanckush

This comment has been minimized.

fanckush commented Feb 5, 2018

lol ok i don't know anymore, update everything :D npm, vue-cli, node

mayble clone this https://github.com/nuxt-community/auth-module/tree/master/example/with-vanilla-nuxt and use it as your base template.

@zalmane

This comment has been minimized.

zalmane commented Feb 5, 2018

For some bizarre reason it seems you have to add axios last (opposite of what it says in doc):

  modules: [
    '@nuxtjs/auth',
    '@nuxtjs/axios'
  ],

@NeOMakinG

This comment has been minimized.

NeOMakinG commented Feb 5, 2018

Nice !! But strange 👍

Thanks you, should have test it before posting there lol

@pi0

This comment has been minimized.

Member

pi0 commented Feb 5, 2018

Hey. Thanks for reporting. This is super strange. With the latest release, it should automatically insert itself just after axios. source (And also tests are doing the same order. Actually order shouldn't matter)

Would you please share contents of .nuxt/index.js when axios is the first item?

@NeOMakinG

This comment has been minimized.

NeOMakinG commented Feb 6, 2018

Hey, No problem !

Here is the index.js file with axios as first :

https://pastebin.com/WyCnJMq5

Looks like axios plugin is imported after Auth one, when Axios is after, in index.js he's imported before auth plugin!

@pi0

This comment has been minimized.

Member

pi0 commented Feb 6, 2018

import nuxt_plugin_authplugin_72500e98 from 'nuxt_plugin_authplugin_72500e98' // Source: ./auth\auth.plugin.js

Ah, i got it! Windows backslash problem again! Will resolve it soon.

pi0 added a commit that referenced this issue Feb 6, 2018

@NeOMakinG

This comment has been minimized.

NeOMakinG commented Feb 6, 2018

Well yeah, sorry for using windob :D

@breakingrobot breakingrobot added this to To Do in 4.0 via automation Feb 13, 2018

@breakingrobot breakingrobot added this to the 4.0 milestone Feb 13, 2018

@breakingrobot breakingrobot moved this from To Do to Done in 4.0 Feb 13, 2018

@busheezy

This comment has been minimized.

busheezy commented Feb 23, 2018

Thanks for finding the problem. I'm running into this, with the latest published release.

@CoolGoose

This comment has been minimized.

CoolGoose commented Feb 25, 2018

The fix with the order of the imports from @zalmane still works.
I'm on windows 10, with a fresh npm install on

"dependencies": {
    "@nuxtjs/auth": "^4.0.0-rc.3",
    "@nuxtjs/axios": "^5.0.1",
    "@nuxtjs/vuetify": "^0.4.0",
    "axios": "^0.18.0",
    "nuxt": "^1.0.0",
    "vuetify": "^1.0.0"
},

Node: v8.9.3 npm 5.6

@CoolGoose

This comment has been minimized.

CoolGoose commented Feb 25, 2018

Actually, it seems that the module resolution errors out incorrectly. Both orders work for the auth/axios
If i don't have the nuxtjs/vuetify entry in the modules it does error out with the error that axios isn't defined.

Nope, I am stupid, order matters, below image is from when it fails.

screen shot 2018-02-25 at 19 26 20-fullpage

syffs added a commit to syffs/auth-module that referenced this issue Feb 26, 2018

@breakingrobot

This comment has been minimized.

Member

breakingrobot commented Mar 12, 2018

Closing as solved by be1bed2.

@g0shed

This comment has been minimized.

g0shed commented Mar 27, 2018

I'm still getting the same error on windows

{ Error: $axios is not available at Auth.get $axios [as $axios] (.nuxt/auth/auth.class.js:93:0) at Auth.setToken (.nuxt/auth/auth.class.js:262:0) at Auth.syncToken (.nuxt/auth/auth.class.js:290:0) at Auth.init (.nuxt/auth/auth.class.js:39:0) at module.exports.__webpack_exports__.a (.nuxt/auth/auth.plugin.js:55:0) at createApp (.nuxt/index.js:166:0) at <anonymous> at process._tickCallback (internal/process/next_tick.js:188:7) statusCode: 500, name: 'NuxtServerError' }

@busheezy

This comment has been minimized.

busheezy commented Mar 27, 2018

@g0shed What version are you using? I don't think we've had an NPM push in a while. A few bugs are fixed and just waiting for an NPM push.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment