nuxt / nuxt/bridge

"external_defu_default(...) is not a function" when defining axios create method in plugin

Open
#455 5 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

pending triage
Dominant language
TypeScript
Stars
285
Forks
33
Avg merge
22h 38m
Merged PRs (30d)
3

Description

Environment

  • Operating System: Darwin
  • Node Version: v14.19.3
  • Nuxt Version: 2.16.0-27616340.013f051b
  • Package Manager: yarn@1.22.18
  • Builder: webpack
  • User Config: head, ssr, css, plugins, components, buildModules, modules, axios, dayjs, vuetify, publicRuntimeConfig, privateRuntimeConfig, storybook, i18n, build, router, serverHandlers, devServerHandlers, bridge
  • Runtime Modules: @nuxtjs/axios@5.13.6, 8n, @nuxtjs/dayjs@1.4.1
  • Build Modules: (), @nuxtjs/stylelint-module@4.1.0, @nuxtjs/vuetify@1.12.3, @pinia/nuxt@0.1.9, @nuxt/bridge@3.0.0-27657000.c87fdbe

Reproduction

https://codesandbox.io/s/confident-wildflower-cjzhey

Describe the bug

I've set a plugin :

export default <Plugin>function ({ app, $axios }, inject: Inject) {
  const snackbarStore = useSnackbarStore()
  const authStore = useAuthStore()

  const api = $axios.create({
    headers: {
      common: {
        Accept: 'application/json',
        'Accept-Language': `${app.i18n.locale}, fr-FR`,
      },
    }
  })

  inject('api', api)
}

On dev mode everything's fine but when I build and start, I got this error :

[nuxt] [request error] external_defu_default(...) is not a function
  at Function.create (./server/chunks/app/server.mjs:22020:59)  
  at plugins_api (./server/chunks/app/server.mjs:22223:26)  
  at createApp (./server/chunks/app/server.mjs:22723:15)  
  at async __webpack_exports__.default (./server/chunks/app/server.mjs:22821:11)  
  at async renderToString (./server/chunks/handlers/renderer.mjs:268:19)  
  at async ./server/chunks/handlers/renderer.mjs:601:20  
  at async ./server/node_modules/h3/dist/index.mjs:417:19  
  at async Server.nodeHandler (./server/node_modules/h3/dist/index.mjs:367:7)

Line 22020 is :

create(options) {
  return createAxiosInstance(external_defu_default()(options, this.defaults));
}
Additional context

No response

Logs

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked CodeSandbox reproduction and the plugin containing $axios.create, then inspect the generated server/chunks/app/server.mjs around line 22020 and the createApp call path. Compare dev and build-and-start behavior, and consider the issue resolved when the production build starts without the external_defu_default(...) error while preserving the plugin's API creation.

Written by the indexing model from the issue text.

Assessment

Tech stack
nuxt, typescript, webpack
Domain
build-system
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.