FormidableLabs / FormidableLabs/use-editable

Identifier "b" has already been declared

Open
#34 0 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
TypeScript
Stars
619
Forks
16
PR merge metrics
No merged PRs in 30d

Description

### Is there an existing issue for this?

- [x] I have searched the existing issues

### Code of Conduct

- [x] I agree to follow this project's Code of Conduct

### Code Sandbox link

_No response_

### Bug report

```markdown
### 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.
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.