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: Cannot read property 'name' of undefined #16

Open
mateusluizfb opened this issue Sep 8, 2023 · 1 comment
Open

TypeError: Cannot read property 'name' of undefined #16

mateusluizfb opened this issue Sep 8, 2023 · 1 comment

Comments

@mateusluizfb
Copy link

I was trying to apply the rule to a file that contains the following require:

const { mongoPort, ...ports } = require('app/ports')

But for some reason, the rule was throwing this error (I removed the full path for privacy purposes):

TypeError: Cannot read property 'name' of undefined
Occurred while linting /Path/to/file/index.js:1
    at getSortableName (/Path/to/file/node_modules/eslint-plugin-require-sort/dist/index.js:179:75)
    at Array.map (<anonymous>)
    at handlePropertySort (/Path/to/file/node_modules/eslint-plugin-require-sort/dist/index.js:107:47)
    at Array.forEach (<anonymous>)
    at ProgramExit (/Path/to/file/node_modules/eslint-plugin-require-sort/dist/index.js:252:44)
    at /Path/to/file/node_modules/eslint/lib/linter/safe-emitter.js:45:58
    at Array.forEach (<anonymous>)
    at Object.emit (/Path/to/file/node_modules/eslint/lib/linter/safe-emitter.js:45:38)
    at NodeEventGenerator.applySelector (/Path/to/file/node_modules/eslint/lib/linter/node-event-generator.js:254:26)
    at NodeEvent

But when I changed the code to the following line, it worked and the error stopped:

const ports = require('app/ports')
const { mongoPort } = ports

Is this error intended, or is it a bug?

@zcuric
Copy link
Owner

zcuric commented Sep 8, 2023

@mateusluizfb Are you sure that you can use a spread operator when requiring a module?

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

No branches or pull requests

2 participants