question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Nuxt3: serialize is not defined

See original GitHub issue

What’s happening

Axios does not seem to work with Nuxt3. Anytime a build is run, it will fail because of an undefined field.

Steps to reproduce

  1. Create a simple Nuxt3 project
  2. npm add @nuxtjs/axios
  3. Add ‘@nuxtjs/axios’ to modules of nuxt.config.js
  4. npm run build

Output

 ERROR  serialize is not defined

  at eval (eval at <anonymous> (node_modules\lodash.template\index.js:1550:12), <anonymous>:52:1)
  at compileTemplate (/C:/Users/Hugo/Documents/Development/scriptio/node_modules/@nuxt/kit/dist/index.mjs:429:45)
  at async /C:/Users/Hugo/Documents/Development/scriptio/node_modules/nuxt3/dist/index.mjs:1092:22
  at async Promise.all (index 13)
  at async generateApp (/C:/Users/Hugo/Documents/Development/scriptio/node_modules/nuxt3/dist/index.mjs:1091:3)
  at async build (/C:/Users/Hugo/Documents/Development/scriptio/node_modules/nuxt3/dist/index.mjs:1128:3)
  at async Object.invoke (/C:/Users/Hugo/Documents/Development/scriptio/node_modules/nuxi-edge/dist/chunks/build.mjs:33:5)
  at async _main (/C:/Users/Hugo/Documents/Development/scriptio/node_modules/nuxi-edge/dist/chunks/index.mjs:384:7)

Here is an issue that might be related: #536.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:17
  • Comments:11

github_iconTop GitHub Comments

37reactions
alisalisocommented, May 9, 2022

I’ve got the same problem with serialize is not defined

// nuxt.config.js
import { defineNuxtConfig } from "nuxt3";

export default defineNuxtConfig({
    env: {
      baseUrl,
    },
    axios: {
      proxy: true,
    },
    proxy: {
      "/api": {
        target: baseUrl,
        pathRewrite: { "^/api/": "api/" },
      },
    },
    modules: ["@nuxtjs/axios", "@nuxtjs/proxy"],
})

My solution

It’s helped to add { proxyHeaders: false } to the modules fom this comment:

modules: [["@nuxtjs/axios", { proxyHeaders: false }], "@nuxtjs/proxy"],

and also baseURL to the axios publicRuntimeConfig from this comment:

publicRuntimeConfig: {
  axios: {
    baseURL: baseUrl,
  },
},
modules: [["@nuxtjs/axios", { proxyHeaders: false }], "@nuxtjs/proxy"],
5reactions
BerkinAKKAYAcommented, May 7, 2022

First time using Nuxt 3, same issue.

My Config:

// nuxt.config.ts
import { defineNuxtConfig } from 'nuxt'

export default defineNuxtConfig({
	modules: [
		'@nuxtjs/axios',
		'@nuxtjs/auth-next'
	],
	router: {
		middleware: ['auth']
	},
	auth: {
		strategies: {
			google: {
				clientId: '...'
			},
		}
	}
})
// tsconfig.json
{
  "extends": "./.nuxt/tsconfig.json",
  "compilerOptions": {
    "types": [
      "@nuxtjs/auth-next",
    ]
  },
}

Error:

Nuxt CLI v3.0.0-rc.2                                                                                                                                                             21:45:01
                                                                                                                                                                                 21:45:01
  > Local:    http://localhost:3000/ 
  > Network:  http://192.168.1.26:3000/
  > Network:  http://192.168.192.1:3000/
  > Network:  http://172.24.0.1:3000/


 ERROR  Error compiling template:  {                                                                                                                                             21:45:09
  src: 'C:\\Users\\Berkin Akkaya\\Desktop\\timeline\\node_modules\\@nuxtjs\\axios\\lib\\plugin.js',
  fileName: 'axios.js',
  options: {
    baseURL: 'http://localhost:3000/',
    browserBaseURL: 'http://localhost:3000/',
    credentials: false,
    debug: false,
    progress: true,
    proxyHeaders: true,
    proxyHeadersIgnore: [
      'accept',
      'cf-connecting-ip',
      'cf-ray',
      'content-length',
      'content-md5',
      'content-type',
      'host',
      'x-forwarded-host',
      'x-forwarded-port',
      'x-forwarded-proto'
    ],
    proxy: false,
    retry: false,
    https: false,
    headers: {
      common: [Object],
      delete: {},
      get: {},
      head: {},
      post: {},
      put: {},
      patch: {}
    },
    globalName: 'nuxt'
  },
  filename: 'axios.js',
  dst: 'C:/Users/Berkin Akkaya/Desktop/timeline/.nuxt/axios.js'
}


 ERROR  Cannot start nuxt:  serialize is not defined                                                                                                                             21:45:09  

  at eval (eval at <anonymous> (node_modules\lodash.template\index.js:1550:12), <anonymous>:52:1)
  at compileTemplate (/C:/Users/Berkin%20Akkaya/Desktop/timeline/node_modules/@nuxt/kit/dist/index.mjs:505:45)
  at async /C:/Users/Berkin%20Akkaya/Desktop/timeline/node_modules/nuxt/dist/index.mjs:1581:22
  at async Promise.all (index 13)
  at async generateApp (/C:/Users/Berkin%20Akkaya/Desktop/timeline/node_modules/nuxt/dist/index.mjs:1580:3)
  at async _applyPromised (/C:/Users/Berkin%20Akkaya/Desktop/timeline/node_modules/perfect-debounce/dist/index.mjs:54:10)


 ERROR  [unhandledRejection] serialize is not defined                                                                                                                            21:45:09  

  at eval (eval at <anonymous> (node_modules\lodash.template\index.js:1550:12), <anonymous>:52:1)
  at compileTemplate (/C:/Users/Berkin%20Akkaya/Desktop/timeline/node_modules/@nuxt/kit/dist/index.mjs:505:45)
  at async /C:/Users/Berkin%20Akkaya/Desktop/timeline/node_modules/nuxt/dist/index.mjs:1581:22
  at async Promise.all (index 13)
  at async generateApp (/C:/Users/Berkin%20Akkaya/Desktop/timeline/node_modules/nuxt/dist/index.mjs:1580:3)
  at async _applyPromised (/C:/Users/Berkin%20Akkaya/Desktop/timeline/node_modules/perfect-debounce/dist/index.mjs:54:10)
Read more comments on GitHub >

github_iconTop Results From Across the Web

nuxtjs/axios What is the way to initialize version 4.4.0? (nuxt.js)
I think it might be because of a problem with asyncData () {}. Also browserBaseURL: '/ api' does not work. javascript · node.js...
Read more >
Setup - Axios Module - nuxtjs/axios
Because of the way Nuxt works the $axios property on the context has to be merged into the Nuxt Context interface via declaration...
Read more >
nuxt-community - Bountysource
Anytime a build is run, it will fail because of an undefined field. Steps to reproduce 1. Create a simple Nuxt3 project 2....
Read more >
【nuxt3】nuxt3配置axios后出现Cannot start nuxt - CSDN博客
【nuxt3】nuxt3配置axios后出现Cannot start nuxt: serialize is not defined. 沉默小管 已于 2022-02-27 20:22:01 修改 2014 收藏 1. 分类专栏: nuxt3 文章标签: ...
Read more >
Nuxt 3 first steps. - ITNEXT
npx nuxi init nuxt3-app · npm install or yarn · [vite:import-analysis] Cannot read property 'uid' of undefined · yarn add -D eslint @typescript-eslint/eslint- ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found