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.

Jest: Cannot use configuration as an object without a file path

See original GitHub issue

I’m getting the error described in this test:

https://github.com/facebook/jest/blob/a43977281802b192b6cdb57a1dc806bdf42169d1/packages/jest-config/src/__tests__/read_config.test.js#L12

I have no clue on what it means or what it wants me to do, I’m trying to use the multi project configuration to run eslint along with the normal tests.

May someone explain this error? I tried to set rootDir in my root config but it doesn’t seem to do anything

This is my config:

{
  "collectCoverageFrom": [
    "src/**/*.{js,jsx,mjs}"
  ],
  "setupFiles": [
    "raf/polyfill",
    "node_modules/react-scripts/config/polyfills.js"
  ],
  "setupTestFrameworkScriptFile": "<rootDir>/src/setupTests.js",
  "testMatch": [
    "<rootDir>/src/**/__tests__/**/*.{js,jsx,mjs}",
    "<rootDir>/src/**/?(*.)(spec|test).{js,jsx,mjs}"
  ],
  "testEnvironment": "node",
  "testURL": "http://localhost",
  "transform": {
    "^.+\\.(js|jsx|mjs)$": "node_modules/react-app-rewired/scripts/utils/babelTransform.js",
    "^.+\\.css$": "node_modules/react-scripts/config/jest/cssTransform.js",
    "^(?!.*\\.(js|jsx|mjs|css|json)$)": "node_modules/react-scripts/config/jest/fileTransform.js"
  },
  "transformIgnorePatterns": [
    "[/\\\\]node_modules(?!/@foobar/react-components)[/\\\\].+\\.(js|jsx)$"
  ],
  "moduleNameMapper": {
    "^.+\\.(css|sss)$": "node_modules/@foobar/react-app-rewire-foobar/node_modules/identity-obj-proxy/src/index.js"
  },
  "moduleFileExtensions": [
    "web.js",
    "mjs",
    "js",
    "json",
    "web.jsx",
    "jsx",
    "node"
  ],
  "rootDir": ".",
  "coverageThreshold": {
    "global": {
      "statements": 100,
      "functions": 100,
      "branches": 100,
      "lines": 100
    }
  },
  "coveragePathIgnorePatterns": [
    "index\\.js$",
    ".*demo\\.jsx$",
    "src/demo/*",
    "src/components/Modal/*"
  ],
  "projects": [
    {
      "displayName": "unit",
      "rootDir": "."
    },
    {
      "displayName": "lint",
      "rootDir": ".",
      "runner": "jest-runner-eslint",
      "testMatch": [
        "<rootDir>/**/*.{js,jsx}"
      ]
    }
  ]
}

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
FezVrastacommented, Feb 16, 2018

The issue is that this error is cryptic and doesn’t help in any way to understand what’s going on… With or without a repro, this error should be improved to help the consumer to understand what’s the required action to fix it.

1reaction
SimeonCcommented, Mar 29, 2018

Hey, I just came across this error too. From digging around the links from @ranyitz I think I figured out why this occurs. Basically my situation is a fork of the test script in create-react-app. Which in essence is: jest.run('--config ' + JSON.stringify(someConfig)). So if I set projects in someConfig to be

[ {
    displayName: 'Typography',
    rootDir: 'packages/Typography'
} ]

which admittedly now that I’m looking through it is not how this is supposed to be used I get the above error. Simply this is because of the following line, which is not defined in a parsed config. https://github.com/facebook/jest/blob/d6192817d59c4a0a84b0d31e3ac9b65f4f5b14f2/packages/jest-cli/src/cli/index.js#L230

I guess what I’m trying to do here is run the same config on multiple projects (a monorepo) and just append the displayName before for easier reporting.

I’m just reading the two very different setups and assuming they could be used together, what I want is probably actually the following but with the ability to add displayNames to it. (Or just completely off the wrong end of this one).

{
  "projects": ["<rootDir>/packages/Typography/src", "<rootDir>/packages/Other/src"]
}

Hopefully, this helps anyone else who hits this particular situation.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Configuring Jest
You can use --config flag to pass an explicit path to the file. note. Keep in mind that the resulting configuration object must...
Read more >
Jest + Typescript + Absolute paths (baseUrl) gives error
This error occurs because of using absolute paths in the import statements of our TypeScript/Nest.js/Angular projects while using Jest. Fixing ...
Read more >
Configuring Jest compiled - w3resource
In this tutorial we will focus on configuring Jest. Jest's configuration can be defined inside the package.json file of your project, ...
Read more >
Config Files - Babel.js
babelrc file, with no extension. package.json files, with a "babel" key. Project-wide configuration.
Read more >
Run/Debug Configuration: Jest | IntelliJ IDEA Documentation
Use --require coffeescript/register to have CoffeeScript files compiled into JavaScript on the fly during run. This mode requires that the ...
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