vuejs / vue-loader

📦 Webpack loader for Vue.js components
MIT License
4.99k stars 915 forks source link

Does not detect 2.7 accurately when exception is thrown #2017

Open thedamon opened 2 years ago

thedamon commented 2 years ago

Version

15.10.1

Reproduction link

codesandbox.io

Steps to reproduce

Use Vue 2.7 and throw a dependency configuration related exception from loadFromContext internal method (in our case we'd forced a specific package version of nanoid to appease a vulnerability scan).

What is expected?

Vue version should be resolved as 2.7 Exception should be logged

What is actually happening?

Vue-loader determines we are using Vue 2.6 or lower and does not compile script setup blocks and no exception is logged


https://github.com/vuejs/vue-loader/blob/v15.10.1/lib/compiler.js#L21

exports.resolveCompiler = function (ctx, loaderContext) {
  if (cached) {
    return cached
  }

  // check 2.7
  try {
    const pkg = loadFromContext('vue/package.json', ctx)
    const [major, minor] = pkg.version.split('.')
    if (major === '2' && Number(minor) >= 7) {
      return (cached = {
        is27: true,
        compiler: loadFromContext('vue/compiler-sfc', ctx),
        templateCompiler: undefined
      })
    }
  } catch (e) {}

Not sure the rationale for the empty catch block here, but perhaps at least errors should be printed? I'll definitely grant that specific resolutions in package.json are buyer-beware, but I do wonder the rationale behind swallowing any errors. Does an error likely mean you are on vue 2.6 or lower? In my case it did not as the exception was totally unrelated to my version of vue.

The minimal repro really only shows the package.json override and doesn't replicate the issue. I spend a long time trying to cobble together the correct versions of things in a code sandbox but I simply did not have time. If there is a "minimal vue 2.7 repro base" somewhere I can totally modify it but what I found on codesandbox was generally out of date. I hope that the description of the issue is fairly straightforward. we had this issue a long time ago and i wanted to report it but couldn't because 15.10.1 was not tagged and my issue submitted without using the issue helper got closed.