node_modules/eslint-plugin-module-resolver/dist/rules/use-alias.js
TypeError: Cannot read property 'loc' of undefined
at CallExpression (./node_modules/eslint-plugin-module-resolver/dist/rules/use-alias.js:112:36)
at listeners.(anonymous function).forEach.listener (./node_modules/eslint/lib/util/safe-emitter.js:47:58)
at Array.forEach (<anonymous>)
at Object.emit (./node_modules/eslint/lib/util/safe-emitter.js:47:38)
at NodeEventGenerator.applySelector (./node_modules/eslint/lib/util/node-event-generator.js:251:26)
at NodeEventGenerator.applySelectors (./node_modules/eslint/lib/util/node-event-generator.js:280:22)
at NodeEventGenerator.enterNode (./node_modules/eslint/lib/util/node-event-generator.js:294:14)
at CodePathAnalyzer.enterNode (./node_modules/eslint/lib/code-path-analysis/code-path-analyzer.js:608:23)
at Traverser.enter [as _enter] (./node_modules/eslint/lib/linter.js:865:28)
at Traverser._traverse (./node_modules/eslint/lib/util/traverser.js:132:14)
at Traverser._traverse (./node_modules/eslint/lib/util/traverser.js:147:30)
at Traverser._traverse (./node_modules/eslint/lib/util/traverser.js:144:34)
at Traverser._traverse (./node_modules/eslint/lib/util/traverser.js:144:34)
at Traverser._traverse (./node_modules/eslint/lib/util/traverser.js:147:30)
at Traverser._traverse (./node_modules/eslint/lib/util/traverser.js:144:34)
at Traverser._traverse (./node_modules/eslint/lib/util/traverser.js:147:30)
Hacking in some debug logging just before it dies:
CallExpression: function CallExpression(node) {
console.warn('CallExpression2:', { node })
context.report({
node: node,
message: message,
loc: node.arguments[0].loc
});
}
It's trying to access node.arguments[0].loc
, but there are no arguments, which is why it crashes:
{ node:
Node {
type: 'CallExpression',
start: 598,
end: 621,
loc: SourceLocation { start: [Object], end: [Object] },
callee:
Node {
type: 'Identifier',
start: 598,
end: 619,
loc: [Object],
name: '_makeShallowComponent',
range: [Array],
_babelType: 'Identifier' },
arguments: [],
range: [ 598, 621 ],
_babelType: 'CallExpression',
parent:
Node {
type: 'VariableDeclarator',
start: 575,
end: 621,
loc: [Object],
id: [Object],
init: [Circular],
range: [Array],
_babelType: 'VariableDeclarator',
parent: [Object] } } }
The snippet of code it appears to be failing on for me is this, nested relatively deep in my jest test:
const { wrappedComponent } = _makeShallowComponent()
It doesn't seem to matter what it is/where it's placed though, as the following as the only thing in the file also causes a failure:
Hacking that line of code to use a proper check lets the error complete, and shows it as:
- 'Unable to find config for babel-plugin-module-resolver'
So I'm thinking maybe this has gotten itself into a weird/undesirable edgecase due to the config being unable to be found, and then it's dying based on an unexpected case there.
Getting super hacky with things, I put the following code in place as per the babel docs:
// var _findBabelConfig$sync = findBabelConfig.sync(babelDir),
// config = _findBabelConfig$sync.config;
var ___babel = require("@babel/core");
var config = ___babel.loadPartialConfig()
console.warn('babelconfig', config)
And it seemed to find my config file (though obviously it's not correctly wired into this rule/plugin properly, just enough to proof of concept):
babelconfig PartialConfig {
// ..snip ..
config: 'my-project-dir/babel.config.js'
}