defu__WEBPACK_IMPORTED_MODULE_3__ is not a function
Asked Answered
T

2

7

Has anyone ever encountered this error when using nuxt-auth from this official guide? How did you solve it? I'm stuck here for days.

The error is defu__WEBPACK_IMPORTED_MODULE_3__ is not a function

Tyrannicide answered 28/5, 2022 at 8:14 Comment(1)
Can you provide your code? Almost your package.json to check dependencies, your nuxt config or something we can check to help youPoeticize
T
26

I had the same issue today with a freshly installed Nuxt 2.15.8 app. Once I added the @nuxtjs/auth-next v.5.0.0-1667386184.dfbbb54 to go with Laravel Sanctum providers the app crashed with same error message. After alot of searching around I found a solution to make the app work again.

In nuxt.config.js add:

build: {
  transpile: [
    'defu'
  ]
}

Hope that helps for you and others having the same issue.

Trematode answered 16/11, 2022 at 15:42 Comment(1)
Big thanks for writing this here!Espresso
E
1

Ran into a similar warning with React early this week, It means you are trying to call a function/access a property of a module that you imported but imported wrongly or it is not exported from the module. webpack throws that error: Similar problem was:

// inside get-user.js
const getUser = () => { 
  const result = localStorage.getItem('user')
  if(result) return JSON.parse(result)
  else return null
}
// Notice: missing export

// inside App.jsx
import getUser from './get-user'
const App = () => {
  const user = getUser()
}

As you can see, inside get-user.js it slipped my mind to add an export for the getUser function. Webpack bundles this but fails later on when I load the App component. A possible cause for your issue:

  1. Missing export for a reusable module you have written.
  2. An issue with next-auth version you are using, Some libraries have breaking changes in a major release, for example, new versions of node-fetch is shipped as ES6 module by default, suggestion is to switch to a lower version(stable) of the package.
  3. Check your export/imports relating to that module in your code if they are correct.

Let me know if that helps, Happy coding!

Epigrammatist answered 28/5, 2022 at 8:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.