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

TypeError within checkBlockScopedCollisions: this.hub is undefined #228

Open
1 task
willsawyerrrr opened this issue May 4, 2023 · 4 comments
Open
1 task

Comments

@willsawyerrrr
Copy link

willsawyerrrr commented May 4, 2023

Your Environment

  • Prettier version: 2.8.8
  • node version: v18.1.0
  • package manager: npm@8.8.0
  • 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

  1. Create the following file1.js:
export const a = "foo";
  1. Create the following file2.js:
import { a } from "./file1";

const a = "bar";
  1. Execute prettier with file2.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 🥇
@ian
Copy link

ian commented Jun 15, 2023

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

@ian
Copy link

ian commented Jun 15, 2023

Nope - that didn't do it.

Tracking upstream issue here: babel/babel#8689

@patric-eberle
Copy link

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: babel/babel#8617

@juxnpxblo
Copy link

I was importing a type called Contact and had a component also called Contact that caused this issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants