Skip to content
Advertisement

Nuxt.js fails to start up with auth module

npx create-nuxt-app client and set it up. Run npm run dev and everything works.

I start auth setup with npm install @nuxtjs/auth

add '@nuxtjs/auth' module in nuxt.config.js

add example auth strategy like so

  auth: {
    strategies: {
      local: {
        endpoints: {
          login: { url: '/api/login', method: 'post' },
        },
        tokenRequired: false,
        tokenType: false
      }
    }
  },

Add the example vue store and save it in store/index.js:

export const state = () => ({
  counter: 0
})

export const mutations = {
  increment(state) {
    state.counter++
  }
}

I run npm run dev, everything compiles and init message shows to go to http://localhost:3000/. Trying to load it in the browser, the URL continues to load after initial loading and does not end. Node process starts to use 100% of the CPU and after several minutes prints this and quits:

<--- Last few GCs --->

[34438:0x38ef0c0]   323677 ms: Scavenge 2003.9 (2048.6) -> 2003.2 (2049.1) MB, 10.9 / 0.0 ms  (average mu = 0.209, current mu = 0.192) allocation failure 
[34438:0x38ef0c0]   323728 ms: Scavenge 2004.6 (2049.6) -> 2004.0 (2049.9) MB, 12.4 / 0.0 ms  (average mu = 0.209, current mu = 0.192) allocation failure 
[34438:0x38ef0c0]   323778 ms: Scavenge 2005.4 (2050.4) -> 2004.8 (2050.6) MB, 10.9 / 0.0 ms  (average mu = 0.209, current mu = 0.192) allocation failure 


<--- JS stacktrace --->

==== JS stack trace =========================================

    0: ExitFrame [pc: 0x13cf019]
Security context: 0x29f654d808d1 <JSObject>
    1: inspect(aka inspect) [0x32d8b34ca9f9] [internal/util/inspect.js:~240] [pc=0xee1e7f4f44c](this=0x1cbf81fc04b1 <undefined>,0x29f654d98bc1 <JSFunction Boolean (sfi = 0x3f35983d3769)>,0x02b5724d8a71 <Object map = 0x1bc8fcdd6919>)
    2: /* anonymous */ [0x9a2eaaec139] [/home/myUserName/Documents/projectFile/client/node_modules/esm/esm.js:~1] [pc=0xee1e7e6e063](...

FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
 1: 0xa093f0 node::Abort() [node]
 2: 0xa097fc node::OnFatalError(char const*, char const*) [node]
 3: 0xb842ae v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [node]
 4: 0xb84629 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [node]
 5: 0xd30fe5  [node]
 6: 0xd31676 v8::internal::Heap::RecomputeLimits(v8::internal::GarbageCollector) [node]
 7: 0xd3def5 v8::internal::Heap::PerformGarbageCollection(v8::internal::GarbageCollector, v8::GCCallbackFlags) [node]
 8: 0xd3eda5 v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [node]
 9: 0xd4185c v8::internal::Heap::AllocateRawWithRetryOrFail(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [node]
10: 0xd0830b v8::internal::Factory::NewFillerObject(int, bool, v8::internal::AllocationType, v8::internal::AllocationOrigin) [node]
11: 0x1049f4e v8::internal::Runtime_AllocateInYoungGeneration(int, unsigned long*, v8::internal::Isolate*) [node]
12: 0x13cf019  [node]
Aborted

I tried this start to finish with node v10.15.3 and v12.18.3, the same result. Versions from package.json:

  "dependencies": {
    "@nuxtjs/auth": "^4.9.1",
    "@nuxtjs/axios": "^5.12.0",
    "bootstrap": "^4.5.0",
    "bootstrap-vue": "^2.15.0",
    "nuxt": "^2.14.0"
  }

and npx create-nuxt-app --version shows create-nuxt-app/3.2.0 linux-x64 node-v12.18.3. OS is Solus 4.1 Fortitude.

What is going wrong here? If this is a known bug, are there versions/workaround that works?

Advertisement

Answer

Setting baseURL property under for axios in nuxt.config.js solved my issue:

  axios: {
    baseURL: '/'
  }
Advertisement