Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Identifier already declared error #223

Closed
prashantpalikhe opened this issue Mar 3, 2023 · 1 comment · Fixed by #250
Closed

Identifier already declared error #223

prashantpalikhe opened this issue Mar 3, 2023 · 1 comment · Fixed by #250
Labels
bug Something isn't working

Comments

@prashantpalikhe
Copy link

prashantpalikhe commented Mar 3, 2023

Environment

unimport: 3.0.2,
npm: '8.1.2',
node: '16.13.2',

Reproduction

https://stackblitz.com/edit/vitejs-vite-z2qfyt

Run npm run build in the project root to reproduce the build error.

Describe the bug

In this repro stackblitz, I have a simple Vite project that uses the vue-ts template. I have included the unimport plugin that uses the Vue preset.

Outside the src folder, I have a my-module module that simulates an npm package.

This module has index.js that contains one of the auto imported function from Vue as a variable name. In the example, I used ref

const u = Object.defineProperty,
  ref = Object.getOwnPropertyNames;

export function getProperties(obj) {
  return ref.call(null, obj);
}

I consume this module in src/main.ts and when I try to build using Vite, I get the following error.

Identifier 'ref' has already been declared

If I were to change the my-module/index.js to this format

const u = Object.defineProperty;
const ref = Object.getOwnPropertyNames;

export function getProperties(obj) {
  return ref.call(null, obj);
}

And rebuild using Vite. Everything goes fine. It seems to have issue when variables are declared like const foo = 'bar', ref = 'baz'.

I can fix this issue my ignoring ref from the import. But similar issues could occur for any other identifier e.g. h

So I think this issue needs to be addressed by unimport itself.

image

Additional context

No response

Logs

Identifier 'ref' has already been declared
file: /home/projects/vitejs-vite-z2qfyt/my-module/index.js:7:0
5: // BREAKS
6: const u = Object.defineProperty,
7:   ref = Object.getOwnPropertyNames;
   ^
8: 
9: export function getProperties(obj) {
error during build:
RollupError: Identifier 'ref' has already been declared
    at error (file://file:///home/projects/vitejs-vite-z2qfyt/node_modules/rollup/dist/es/shared/node-entry.js:2130:30)
    at Module.error (file://file:///home/projects/vitejs-vite-z2qfyt/node_modules/rollup/dist/es/shared/node-entry.js:13199:16)
    at Module.tryParse (file://file:///home/projects/vitejs-vite-z2qfyt/node_modules/rollup/dist/es/shared/node-entry.js:13876:25)
    at Module.setSource (file://file:///home/projects/vitejs-vite-z2qfyt/node_modules/rollup/dist/es/shared/node-entry.js:13486:39)
    at ModuleLoader.addModuleSource (file://file:///home/projects/vitejs-vite-z2qfyt/node_modules/rollup/dist/es/shared/node-entry.js:23447:20)
@antfu antfu added the bug Something isn't working label Mar 6, 2023
@steveworkman
Copy link

+1 on this bug, a recent upgrade to nuxt 3.5 (from 3.1) and code from my internal component library now exhibits the h has already been declared issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants