`TypeError` within `checkBlockScopedCollisions`: `this.hub` is undefined
Your Environment
- Prettier version: 2.8.8
- node version: v18.1.0
- package manager: [email protected]
- IDE: VSCode/Vim (independent of editor)
Describe the bug
When importing a symbol and declaring a duplicate identifier, checkBlockScopedCollisions is called, correctly identifying the duplicate identifier; however, when attempting to throw this.hub.buildError, this.hub is undefined.
To Reproduce
- Create the following
file1.js:
export const a = "foo";
- Create the following
file2.js:
import { a } from "./file1";
const a = "bar";
- Execute
prettierwithfile2.js:
npx prettier file2.js
Expected behavior
A SyntaxError should be raised, similarly to the result of executing Prettier with the following file3.js:
const a = "foo";
const a = "bar";
Screenshots, code sample, etc
N/A
Configuration File (cat .prettierrc, prettier.config.js, .prettier.js)
N/A
Error log
[error] file2.js: TypeError: Cannot read properties of undefined (reading 'buildError')
[error] at Scope.checkBlockScopedCollisions (./node_modules/@babel/traverse/lib/scope/index.js:473:22)
[error] at Scope.registerBinding (./node_modules/@babel/traverse/lib/scope/index.js:634:16)
[error] at Scope.registerDeclaration (./node_modules/@babel/traverse/lib/scope/index.js:575:14)
[error] at Object.BlockScoped (./node_modules/@babel/traverse/lib/scope/index.js:292:12)
[error] at Object.newFn (./node_modules/@babel/traverse/lib/visitors.js:218:17)
[error] at NodePath._call (./node_modules/@babel/traverse/lib/path/context.js:53:20)
[error] at NodePath.call (./node_modules/@babel/traverse/lib/path/context.js:36:14)
[error] at NodePath.visit (./node_modules/@babel/traverse/lib/path/context.js:100:31)
[error] at TraversalContext.visitQueue (./node_modules/@babel/traverse/lib/context.js:103:16)
[error] at TraversalContext.visitMultiple (./node_modules/@babel/traverse/lib/context.js:72:17)
Contribute to @trivago/prettier-plugin-sort-imports
- [ ] I'm willing to fix this bug 🥇
Experiencing the same issue.
I think the solution here is bumping the @babel/traverse version. Currently it's hard locked to 7.17.3 but latest is 7.22.5
Nope - that didn't do it.
Tracking upstream issue here: https://github.com/babel/babel/issues/8689
I had the same issue with a conflicting named function in a TS file.
import { InitialData } from './file-a.ts';
// The function identical name in this file caused the conflict
export default function InitialData(): InitialData {}
I think this is the related Babel bug: https://github.com/babel/babel/issues/8617
I was importing a type called Contact and had a component also called Contact that caused this issue