-
Notifications
You must be signed in to change notification settings - Fork 50.3k
Closed
Labels
Resolution: Needs More InformationStatus: UnconfirmedA potential issue that we haven't yet confirmed as a bugA potential issue that we haven't yet confirmed as a bug
Description
eslint-plugin-react-hooks is throwing a Cannot read property 'references' of undefined error on /node_modules/eslint-plugin-react-hooks/cjs/eslint-plugin-react-hooks.development.js:1683:23
I added a console log statement before that line
var usedDep = dependencies.get(missingDep);
console.log('usedDep', usedDep, missingDep, dependencies)
if (usedDep.references[0].resolved !== topScopeRef) { // error is thrown here
and this is the output.
usedDep undefined program?.slug Map {
'program?.uuid' => { isStatic: false, references: [ [Reference] ] },
'monitorService' => { isStatic: false, references: [ [Reference] ] },
'navigate' => { isStatic: false, references: [ [Reference] ] },
'program.slug' => { isStatic: false, references: [ [Reference] ] } }
I don't actually have program?.slug referenced anywhere in this file.
I am using program.slug though.
Versions:
eslint-plugin-react-hooks@4.0.4
eslint@6.8.0
babel-eslint@10.1.0
Steps To Reproduce
The code below throws the error.
I have found 2 ways to stop the error from happening.
- Removing the line
programUuid: program?.uuid ?? '', - adding
program.slugto the list of dependencies.
Link to code example:
const onSave = useCallback(
args => {
const request: CreateMonitorV3Request = {
programUuid: program?.uuid ?? '',
};
monitorService
.create(request)
.then(x => {
// $FlowFixMe - program will be available
navigate(`/programs/${program.slug}/monitors/${x.uuid}`);
})
.catch(ex => {
console.log('error', ex);
});
},
[monitorService, program?.uuid]
);
The current behavior
Error is thrown Cannot read property 'references' of undefined
The expected behavior
eslint successfully reports that I'm missing dependencies in useCallback
Full Stack trace:
TypeError: Cannot read property 'references' of undefined
Occurred while linting /project-root/src/pages/monitor/configuration-pages/new-monitor-page.js:26
at /project-root/node_modules/eslint-plugin-react-hooks/cjs/eslint-plugin-react-hooks.development.js:1683:23
at Set.forEach (<anonymous>)
at visitFunctionWithDependencies (/project-root/node_modules/eslint-plugin-react-hooks/cjs/eslint-plugin-react-hooks.development.js:1674:29)
at visitCallExpression (/project-root/node_modules/eslint-plugin-react-hooks/cjs/eslint-plugin-react-hooks.development.js:826:11)
at listeners.(anonymous function).forEach.listener (/project-root/node_modules/eslint/lib/linter/safe-emitter.js:45:58)
at Array.forEach (<anonymous>)
at Object.emit (/project-root/node_modules/eslint/lib/linter/safe-emitter.js:45:38)
at NodeEventGenerator.applySelector (/project-root/node_modules/eslint/lib/linter/node-event-generator.js:254:26)
at NodeEventGenerator.applySelectors (/project-root/node_modules/eslint/lib/linter/node-event-generator.js:283:22)
at NodeEventGenerator.enterNode (/project-root/node_modules/eslint/lib/linter/node-event-generator.js:297:14)
Thisen, Voronar, Cirych, deasems, tcodes0 and 3 more
Metadata
Metadata
Assignees
Labels
Resolution: Needs More InformationStatus: UnconfirmedA potential issue that we haven't yet confirmed as a bugA potential issue that we haven't yet confirmed as a bug