unplugin-vue-components icon indicating copy to clipboard operation
unplugin-vue-components copied to clipboard

When the global variable and function definition parameter have the same name, the function parameter will be overwritten by the global variable. After troubleshooting, it is caused by the unplugin vue components plugin. Removing this plugin is normal

Open WormGirl opened this issue 2 years ago • 12 comments

Describe the bug

When the global variable and function definition parameter have the same name, the function parameter will be overwritten by the global variable. After troubleshooting, it is caused by the unplugin vue components plugin. Removing this plugin is normal

<script setup lang="ts">
const a = 3
function test(a: Number, b: Number) {
  // a的值应该是1才对  实际变成了3 有点离谱, 删掉unplugin-vue-components插件就正常了
  console.log(a, b)
}
</script>

<template>
  <button @click="test(1, 2)">
    点我可复现
  </button>
</template>

Reproduction

https://github.com/WormGirl/bug-report-unplugin-vue-components

System Info

System:
    OS: Windows 10 10.0.19043
    CPU: (16) x64 Intel(R) Core(TM) i7-10700 CPU @ 2.90GHz   
    Memory: 16.88 GB / 31.79 GB
  Binaries:
    Node: 16.20.1 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.17 - ~\AppData\Roaming\npm\yarn.CMD
    npm: 8.19.4 - C:\Program Files\nodejs\npm.CMD
    pnpm: 8.6.10 - ~\AppData\Local\pnpm\pnpm.CMD
  Browsers:
    Edge: Spartan (44.19041.1266.0), Chromium (116.0.1938.62)
    Internet Explorer: 11.0.19041.1566

Used Package Manager

pnpm

Validations

  • [X] Follow our Code of Conduct
  • [X] Read the Contributing Guide.
  • [X] Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
  • [X] Check that this is a concrete bug. For Q&A, please open a GitHub Discussion instead.
  • [X] The provided reproduction is a minimal reproducible of the bug.

WormGirl avatar Aug 31 '23 06:08 WormGirl

兄弟,你这个依赖安装不成功啊,确定 package.json 里面没有包含私有仓库的包

lishaobos avatar Sep 04 '23 02:09 lishaobos

兄弟,你这个依赖安装不成功啊,确定 package.json 里面没有包含私有仓库的包

抱歉,是有几个私有的忘了删了,更新了,你重新拉下

WormGirl avatar Sep 04 '23 09:09 WormGirl

兄弟,我这边没问题,你要么删除掉 lock 文件再安装试试?

image

lishaobos avatar Sep 05 '23 02:09 lishaobos

兄弟,我这边没问题,你要么删除掉 lock 文件再安装试试?

image

兄弟,我这边没问题,你要么删除掉 lock 文件再安装试试?

image

兄弟,我上次就是删掉lock文件重装的

WormGirl avatar Sep 05 '23 07:09 WormGirl

我打印的也是1 2 ,你加个debugger看看 ,很离谱的,运行时是3,2 GIF 2023-9-5 15-21-13

WormGirl avatar Sep 05 '23 07:09 WormGirl

const a = 3
function test(a: Number, b: Number) {
  // a的值应该是1才对  实际变成了3 有点离谱
  // eslint-disable-next-line no-debugger, no-restricted-syntax
  debugger
  console.log(a, b)
}

WormGirl avatar Sep 05 '23 07:09 WormGirl

这个应该是 sourcemap 生成或者是 chrome 的问题:

你 debugger 源代码,函数 a 变量实则成为了 a2,所以会指向上面的 a,你自己打印 a2,还是 1,我觉得这个不用过多纠结

image image

lishaobos avatar Sep 05 '23 07:09 lishaobos

但是我删掉这个插件debugger就正常了 这是咋回事

WormGirl avatar Sep 05 '23 07:09 WormGirl

感觉还是和这个插件有点关系

WormGirl avatar Sep 05 '23 07:09 WormGirl

你把vite.config.ts里unplugin-vue-components/vite相关的删掉看下

WormGirl avatar Sep 05 '23 07:09 WormGirl

重新验证了 就是debugger的时候不对 实际运行结果符合预期。。。可以的话还是麻烦看下啥原因 debugger不对也影响开发

WormGirl avatar Sep 05 '23 08:09 WormGirl

提交 pr 了,是 sourceMap 精细度不够,等通过就好了

lishaobos avatar Sep 05 '23 09:09 lishaobos