-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Closed
Labels
Description
Hi,
I get "TypeError: Cannot read property 'name' of undefined" when importing an index.d.ts with export = AnalyticsNode.Analytics;
:
I have "eslint-plugin-import": "^2.22.0" (which fixed #1818) I still get:
TypeError: Cannot read property 'name' of undefined
Occurred while linting /home/dani/hubtype/botonic/packages/botonic-cli/src/utils.ts:5
at /home/dani/hubtype/botonic/node_modules/eslint-plugin-import/lib/ExportMap.js:712:221
at Array.forEach (<anonymous>)
at Function.ExportMap.parse (/home/dani/hubtype/botonic/node_modules/eslint-plugin-import/lib/ExportMap.js:706:248)
at Function.ExportMap.for (/home/dani/hubtype/botonic/node_modules/eslint-plugin-import/lib/ExportMap.js:699:201)
at Function.ExportMap.get (/home/dani/hubtype/botonic/node_modules/eslint-plugin-import/lib/ExportMap.js:693:370)
at checkDefault (/home/dani/hubtype/botonic/node_modules/eslint-plugin-import/lib/rules/default.js:22:41)
It happens when importing a namespace from this file:
"analytics-node": "^3.4.0-beta.1",
"@types/analytics-node": "^3.1.3",
I added
console.log("exp", n.expression, n.expression.name, n.expression.id);
before
const exportedName = n.type === 'TSNamespaceExportDeclaration'
in ExportMap, and I got:
exp {
type: 'MemberExpression',
object: {
type: 'Identifier',
name: 'AnalyticsNode',
range: [ 379, 392 ],
loc: { start: [Object], end: [Object] }
},
property: {
type: 'Identifier',
name: 'Analytics',
range: [ 393, 402 ],
loc: { start: [Object], end: [Object] }
},
computed: false,
optional: false,
range: [ 379, 402 ],
loc: { start: { line: 8, column: 9 }, end: { line: 8, column: 32 } }
} undefined undefined
It crashes because the expression has no name nor id fields.
I tried hard to generate a small test case, but I could not reproduce the issue then.
My workaround to avoid the crash was removing this
settings: {
'import/parsers': {
'@typescript-eslint/parser': ['.ts', '.tsx', '.d.ts'],
},