`TypeError: Cannot read property 'concat' of undefined` when running ESLint via Jest
See original GitHub issueThis error occurs when running ESLint from a Jest test:
TypeError: Cannot read property 'concat' of undefined
at Object.<anonymous> (/Users/spencerelliott/Sites/elliottsj/eslint-jest-issue-5791/node_modules/eslint/lib/util/module-resolver.js:28:30)
at Object.<anonymous> (/Users/spencerelliott/Sites/elliottsj/eslint-jest-issue-5791/node_modules/eslint/lib/config/config-file.js:23:22)
at Object.<anonymous> (/Users/spencerelliott/Sites/elliottsj/eslint-jest-issue-5791/node_modules/eslint/lib/config.js:17:18)
at Object.<anonymous> (/Users/spencerelliott/Sites/elliottsj/eslint-jest-issue-5791/node_modules/eslint/lib/cli-engine.js:31:14)
at Object.<anonymous> (/Users/spencerelliott/Sites/elliottsj/eslint-jest-issue-5791/node_modules/eslint/lib/api.js:10:16)
at Object.<anonymous> (/Users/spencerelliott/Sites/elliottsj/eslint-jest-issue-5791/src/index.js:1:136)
at Object.<anonymous> (/Users/spencerelliott/Sites/elliottsj/eslint-jest-issue-5791/src/__tests__/index-test.js:3:12)
at jasmine2 (/Users/spencerelliott/Sites/elliottsj/eslint-jest-issue-5791/node_modules/jest-jasmine2/src/index.js:154:16)
What version of ESLint are you using?
eslint@2.7.0
What parser (default, Babel-ESLint, etc.) are you using? default
Please show your full configuration: https://github.com/elliottsj/eslint-jest-issue-5791/blob/master/.eslintrc
{
"extends": "eslint:recommended",
"env": {
"jest": true,
"node": true
}
}
What did you do? Please include the actual source code causing the issue.
See the full example here: https://github.com/elliottsj/eslint-jest-issue-5791
// index.js
var CLIEngine = require('eslint').CLIEngine;
function lint() {
var cli = new CLIEngine();
// Lint this file
var report = cli.executeOnFiles(['index.js']);
return report;
}
module.exports = {
lint: lint
};
// __tests__/index-test.js
jest.unmock('..');
var lint = require('..').lint;
describe('eslint CLIEngine', function() {
it('should work with Jest\'s module system', function() {
var report = lint();
expect(report.results).toBeDefined();
});
});
What did you expect to happen?
Expected the Jest test to pass without error.
What actually happened? Please include the actual, raw output from ESLint.
See error shown above.
ESLint v2.5.3 runs fine: https://github.com/elliottsj/eslint-jest-issue-5791/tree/eslint-2.5
It seems the issue was introduced as a result of https://github.com/eslint/eslint/commit/4ecd45e549c8622a26f5b105dd43b7a2827cf942: here is the failing line: https://github.com/eslint/eslint/commit/4ecd45e549c8622a26f5b105dd43b7a2827cf942#diff-6535c964600bdcc5abbfefe8282e96f3R28
Issue Analytics
- State:
- Created 7 years ago
- Comments:10 (5 by maintainers)
Top GitHub Comments
This was fixed in Jest 11.0.
@nzakas Is there a reason why eslint is using module.paths at all? It seems like it is undocumented private API that is an implementation detail of the node module resolution algorithm.
Jest sandboxes all JavaScript code for proper test isolation (that way no module or test can impact another test). We are using node-resolve for all resolution which has a userland implementation of what
module.paths
gives you. I suggest to use it instead: https://github.com/substack/node-resolve