6

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..?

4 Answers 4

6

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.

Sign up to request clarification or add additional context in comments.

Comments

5

It seems you use old version of vue_cli.

Solution:

UPGRADE YOUR VUE CLI TO LATEST VERSION

Go to package.json and change @vue/cli-service to latest version

"@vue/cli-service": "^5.0.8",

Then will work, thanks.

Comments

1

The defineConfig function is available in @vue/cli-service v5 but not v4. I had the same problem and updating to v5 fixed the problem. You can also see it explicitly mentioned in the Vue CLI docs (so it isn't specific to Vite).

Comments

0

well, for me I uninstalled recently installed package and then retried it should work 95% of the times.

once build is successful reinstall the packages with right versions. this should solve the issue

all the best

1 Comment

As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.