vue.jsvuejs3

defineConfig is undefined when required from @vue/cli-service - vue.config.js


I'm trying to set up my vue.config.js file and found that issue when I use defineConfig method from @vue/cli-service.

TypeError: defineConfig is not a function

vue.config.js

const { defineConfig } = require('@vue/cli-service')

module.exports = defineConfig({
  devServer: {
    port: 3001,
  },
});

defineConfig is undefined. I was trying to look for it in cli-service folder, but (as suppose) there is no such method.

I'm using vue.js 3, yarn 1.22.17 and my @vue/cli version is 4.5.15. Is it possible that defineConfig is for @vue/cli version 5..?


Solution

  • defineConfig macro is used by Vue CLI 5 not by Vue CLI 4, the right syntax for vue cli 4:

    module.exports = {
      devServer: {
        port: 3001,
      },
    };
    

    You should upgrade to be able to use this macro.