Skip to content
New issue

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

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

Already on GitHub? # to your account

Identifier "b" has already been declared #34

Open
2 tasks done
LaymanTeam opened this issue Jan 18, 2025 · 0 comments · May be fixed by #35
Open
2 tasks done

Identifier "b" has already been declared #34

LaymanTeam opened this issue Jan 18, 2025 · 0 comments · May be fixed by #35
Labels
bug Something isn't working

Comments

@LaymanTeam
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

Code of Conduct

  • I agree to follow this project's Code of Conduct

Code Sandbox link

No response

Bug report

### What Does This Error Mean?

The error:


Identifier "b" has already been declared


indicates that the variable `b` has been declared multiple times in the same scope. This violates JavaScript's scoping rules, causing a syntax error during the build process. The issue originates from the `use-editable` package, specifically in the file:


/node_modules/use-editable/dist/use-editable.es.js


The problem is in this line:


"undefined" != typeof MutationObserver && (e.observer = new MutationObserver((function b(b) {


Here, `b` is both the name of the function and its parameter, creating a conflict.

---

### Which Module is Responsible?

The error is caused by the `use-editable` package, which appears to have a bug in its distributed code (`dist/use-editable.es.js`).

---

### How to Fix It


####  **Patch the Package**

If an updated version isn't available or doesn't fix the issue, you can patch the package locally:

1. Install `patch-package`:

   
   npm install patch-package --save-dev
   

2. Locate the problematic file:

   
   node_modules/use-editable/dist/use-editable.es.js
   

3. Edit the file to rename the conflicting identifier. For example, change:

   
   (function b(b) { ... });
   

   to:

   
   (function handleMutation(mutations) { ... });
   

4. Create a patch:

   
   npx patch-package use-editable
   

5. Add `patch-package` to your `postinstall` script in `package.json`:

   
   "scripts": {
     "postinstall": "patch-package"
   }
   

---

#### 3. **Use Vite Plugin to Handle Legacy Code**

If modifying the package isn't an option, use Vite's `optimizeDeps` to handle problematic dependencies. Add this to `vite.config.js`:


export default defineConfig({
  optimizeDeps: {
    include: ['use-editable']
  }
});


---


### Summary

- The error is caused by a bug in the `use-editable` package.
- Update the package, patch it locally, or configure Vite to handle it.

These steps should help resolve the build error effectively.
@LaymanTeam LaymanTeam added the bug Something isn't working label Jan 18, 2025
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working
Projects
None yet
1 participant