Joshua Avery
Joshua Avery

Reputation: 324

How do I install vue router plugin with Vue CLI 3?

So I've been setting up projects with the Vue CLI 3.0.0rc8 and it is a pretty awesome tool but I have a problem. I am trying to install the router plugin for my project however when I use vue add router, I get this:

(node:2706) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'routerHistoryMode' of undefined
at module.exports (/home/joshua/programs/firstwebapp/frontend/node_modules/@vue/cli-service/generator/router/index.js:10:26)
at Generator.plugins.forEach (/home/joshua/.node_modules_global/lib/node_modules/@vue/cli/lib/Generator.js:96:7)
at Array.forEach (<anonymous>)
at new Generator (/home/joshua/.node_modules_global/lib/node_modules/@vue/cli/lib/Generator.js:94:13)
at Function.runGenerator (/home/joshua/.node_modules_global/lib/node_modules/@vue/cli/lib/invoke.js:111:21)
at process._tickCallback (internal/process/next_tick.js:68:7)
(node:2706) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:2706) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Could someone please explain why this isn't working?

P.S. I've also tried vue add @vue/router and I get the same message.

Upvotes: 3

Views: 1695

Answers (2)

Joshua Avery
Joshua Avery

Reputation: 324

I've got it! Thank you to @dnhyde for your suggestion. But if you actually want to install it as a plugin you need to update the Vue CLI to 3.0.0-rc.10. Do so with this command: npm i -g @vue/cli.

Upvotes: 3

dnhyde
dnhyde

Reputation: 1305

Hi I had a similar issue, the best way to add Vue router in my case was to select it from the start with vue create my-project command. Or you can manually add the router.js file and the Vue.use(router) in your main following the template vue-cli creates for you.

Upvotes: 0

Related Questions