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

Neville Lemein
  • 177
  • 1
  • 9
  • Can you provide your code? Almost your package.json to check dependencies, your nuxt config or something we can check to help you – thebyteland Aug 04 '22 at 23:38

2 Answers2

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.

tjaydk
  • 281
  • 3
  • 8
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!

nmurgor
  • 402
  • 4
  • 8