From f2c2fe1403fed8559f3863b412b574df2fe46baf Mon Sep 17 00:00:00 2001 From: Haoqun Jiang Date: Tue, 11 Aug 2020 15:06:26 +0800 Subject: [PATCH 1/2] fix: load vue from `@vue/cli-service-global` on `vue serve`/`vue build` Fixes #5773 --- packages/@vue/cli-service/lib/config/base.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/@vue/cli-service/lib/config/base.js b/packages/@vue/cli-service/lib/config/base.js index 8d45f69bcc..5fdb8ca74f 100644 --- a/packages/@vue/cli-service/lib/config/base.js +++ b/packages/@vue/cli-service/lib/config/base.js @@ -69,7 +69,9 @@ module.exports = (api, options) => { // js is handled by cli-plugin-babel --------------------------------------- // vue-loader -------------------------------------------------------------- - const vue = loadModule('vue', api.service.context) + // try to load vue in the project + // use fallback require in the instant prototyping environment + const vue = loadModule('vue', api.service.context) || require('vue') if (semver.major(vue.version) === 2) { // for Vue 2 projects From 449147734ca4883595e6c058bc2617b8aa20a65e Mon Sep 17 00:00:00 2001 From: Haoqun Jiang Date: Tue, 11 Aug 2020 16:39:35 +0800 Subject: [PATCH 2/2] fix: use `loadModule` as vue's not a explict peer dependency in this package --- packages/@vue/cli-service/lib/config/base.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/@vue/cli-service/lib/config/base.js b/packages/@vue/cli-service/lib/config/base.js index 5fdb8ca74f..343a46cffc 100644 --- a/packages/@vue/cli-service/lib/config/base.js +++ b/packages/@vue/cli-service/lib/config/base.js @@ -70,10 +70,10 @@ module.exports = (api, options) => { // vue-loader -------------------------------------------------------------- // try to load vue in the project - // use fallback require in the instant prototyping environment - const vue = loadModule('vue', api.service.context) || require('vue') + // fallback to peer vue package in the instant prototyping environment + const vue = loadModule('vue', api.service.context) || loadModule('vue', __dirname) - if (semver.major(vue.version) === 2) { + if (vue && semver.major(vue.version) === 2) { // for Vue 2 projects const vueLoaderCacheConfig = api.genCacheConfig('vue-loader', { 'vue-loader': require('vue-loader/package.json').version, @@ -108,7 +108,7 @@ module.exports = (api, options) => { webpackConfig .plugin('vue-loader') .use(require('vue-loader').VueLoaderPlugin) - } else if (semver.major(vue.version) === 3) { + } else if (vue && semver.major(vue.version) === 3) { // for Vue 3 projects const vueLoaderCacheConfig = api.genCacheConfig('vue-loader', { 'vue-loader': require('vue-loader-v16/package.json').version,