question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`TypeError: Cannot read property 'concat' of undefined` when running ESLint via Jest

See original GitHub issue

This 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:closed
  • Created 7 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

4reactions
cpojercommented, Apr 14, 2016

This was fixed in Jest 11.0.

1reaction
cpojercommented, Apr 18, 2016

@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

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeError: Cannot read property 'concat' of undefined
My problem is that when i run my project it gives me an error that says: TypeError: Cannot read property 'concat' of undefined....
Read more >
error typeerror: cannot read properties of undefined ... - You.com
When I try to write data to firebase, this is the console error I get: ERROR TypeError: Cannot read properties of undefined (reading...
Read more >
Cannot Read Property 'split' of Undefined - freeCodeCamp
If you've ever used JavaScript's split method, there's a good chance that you've encountered the following error: TypeError: Cannot read ...
Read more >
jest-environment-jsdom | Yarn - Package Manager
Jest will set process.env.NODE_ENV to 'test' if it's not set to something else. You can use that in your configuration to conditionally setup...
Read more >
The starting point for learning TypeScript
A great first read for your daily TS work. The TypeScript Handbook · The Basics · Everyday Types · Narrowing · More on...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found