vue-cli: Cannot read property 'version' of undefined

Version

3.1.0

Node and OS info

Node v10.13.0 / npm 6.4.1

Steps to reproduce

npm install -g @vue/cli npm install -g @vue/cli-service-global

What is expected?

vue serve should start the prototyping server

What is actually happening?

(node:15758) UnhandledPromiseRejectionWarning: TypeError: Cannot read property ‘version’ of undefined at module.exports (/usr/local/lib/node_modules/@vue/cli-service-global/node_modules/@vue/cli-plugin-eslint/index.js:20:29) at plugins.forEach (/usr/local/lib/node_modules/@vue/cli-service-global/node_modules/@vue/cli-service/lib/Service.js:79:7) at Array.forEach (<anonymous>) at Service.init (/usr/local/lib/node_modules/@vue/cli-service-global/node_modules/@vue/cli-service/lib/Service.js:78:18) at Service.run (/usr/local/lib/node_modules/@vue/cli-service-global/node_modules/@vue/cli-service/lib/Service.js:204:10) at Object.exports.serve (/usr/local/lib/node_modules/@vue/cli-service-global/index.js:54:33) at Command.program.command.description.option.option.action (/usr/local/lib/node_modules/@vue/cli/bin/vue.js:104:53) at Command.listener (/usr/local/lib/node_modules/@vue/cli/node_modules/commander/index.js:315:8) at Command.emit (events.js:182:13) at Command.parseArgs (/usr/local/lib/node_modules/@vue/cli/node_modules/commander/index.js:654:12) (node:15758) 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:15758) [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.


Following this tutorial https://cli.vuejs.org/guide/prototyping.html

cli-plugin-eslint api directory getting resolved as current project directory https://github.com/vuejs/vue-cli/blob/dev/packages/%40vue/cli-plugin-eslint/index.js#L8 and so eslintPkg becomes undefined.

I added plugin to the current directory by vue add @vue/eslint and dev server started normally.

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 11
  • Comments: 36 (15 by maintainers)

Most upvoted comments

Just do npm install eslint inside the project. It should work.

Fixed in the latest release. Please reinstall the @vue/cli-service-global package.

Just do npm install eslint inside the project. It should work.

Thank you for that! Still curious as to why this solves the issue and why it’s not documented.

In Addition to @OriginalEXE I also needed to add those as local packages:

npm install eslint-plugin-vue
npm install babel-eslint

@AuspeXeu

  1. If you are experiencing this error with vue serve, I’ve no idea how this happened because this bug should not exist in either 3.12.1 or the latest 4.0.5
  2. If it’s yarn serve or npm run serve, then it’s because eslint is not added to your project (I don’t see it in the listed devDependencies fields above). That’s also weird because any new project scaffolded with Vue CLI 3.1.0 (which was released a year ago) or later should have eslint in devDependencies. And if you follow the migration guide to upgrade the project to v4, eslint should also have been added.

eslint is now a peer dependency so you need to install it yourself for the project:

npm install --save-dev eslint@5

I had same problem but solved it by simply running yarn install or npm install. I hope someone out there will find this helpful.

@mikizdr To be fair Vue CLI v4 is in prerelease for half a year already. 6 alphas, 4 betas, 9 RCs, and not a single issue has been raised on this problem. We are definitely very serious about this project and not getting users to test production release. Bug happens, no matter how hard you try.

Of course, we should try to fix bugs as soon as possible and avoid silly problems to happen again.

But there are priorities. I didn’t fix this one so soon because:

  1. I didn’t realize it’s a bug until late Friday night in my timezone;
  2. vue serve is not recommended for production use in our documentation https://cli.vuejs.org/guide/prototyping.html So I assume it doesn’t break production apps;
  3. There are workarounds in the above comments;
  4. I’ve only just located the bug but not yet sure how to fix, it takes time to think about.

And, if you do have a solution, PR is welcome.

I am using @vue/cli 4.0.4 @vue/cli-service-global 4.0.4 Have the same issue and solved it by npm install -D eslint eslint-plugin-vue babel-eslint

Must be introduced by this commit https://github.com/vuejs/vue-cli/commit/c50051262f4217dc0faa7883912b2e816798070d I’ll try to fix it asap.

@joeirimpan solves the issue, but how come?