Jest: babel-jest throwing ReferenceError due to unknown configuration option

Created on 1 Feb 2019  ยท  6Comments  ยท  Source: facebook/jest

๐Ÿ› Bug Report

babel-jest is erroring out every time I try to transform some of my TypeScript files. The specific error is:

ReferenceError: [BABEL] redacted\accelerator-core\config\testing\setupTests.ts: Unknown option: redacted\accelerator-core\node_modules\babel-preset-react-app\index.js.overrides. Check out http://babeljs.io/docs/usage/options/ for more information about options.

    A common cause of this error is the presence of a configuration options object without the corresponding preset name. Example:

    Invalid:
      `{ presets: [{option: value}] }`
    Valid:
      `{ presets: [['presetName', {option: value}]] }`

    For more detailed information on preset configuration, please see https://babeljs.io/docs/en/plugins#pluginpresets-options. (While processing preset: "redacted\\accelerator-core\\node_modules\\babel-preset-react-app\\index.js")

The specific failure seems to be that OptionManager.prototype.mergeOptions in babel-jest expects to see an overrides property in babel-core/lib/transformation/file/optionsconfig.js. When this is not found, it throws.

To Reproduce

Steps to reproduce the behavior:

  • Check out the dev branch.
  • npm install
  • npm t.

Expected behavior

I expect the files to be transformed correctly and for babel-jest not to throw an error.

Link to repl or repo (highly encouraged)

https://github.com/furkleindustries/accelerator-core

Run npx envinfo --preset jest

System:
    OS: Windows 10
    CPU: (8) x64 Intel(R) Core(TM) i7-6700HQ CPU @ 2.60GHz
Binaries:
    Node: 8.9.4 - C:\Program Files\nodejs\node.EXE
    npm: 6.5.0 - C:\Program Files\nodejs\npm.CMD
Bug

Most helpful comment

Ah right! ๐Ÿ˜…

I keep getting [Error: ENOENT: no such file or directory, open '/Users/simen/repos/accelerator-core/passages/passages-manifest.ts'], btw.

Beyond that though, your error is due to jest locating the wrong babel-jest. Either running npm dedupe will fix it, or this diff to your config:

diff --git i/config/testing/jest.config.js w/config/testing/jest.config.js
index 46bccb0..fb75f43 100644
--- i/config/testing/jest.config.js
+++ w/config/testing/jest.config.js
@@ -20,7 +20,7 @@ module.exports = {
   ],

   transform: {
-    '^.+\\.[jt]sx?$': 'babel-jest',
+    '^.+\\.[jt]sx?$': require.resolve('babel-jest'),
     '^.+\\.css$': '<rootDir>/config/testing/cssTransform.js',
     '^(?!.*\\.(js|jsx|ts|tsx|css|json)$)': '<rootDir>/config/testing/fileTransform.js',
   },

All 6 comments

I don't get an error when running your reproduction

$ npm t -- --dontWatch

> [email protected] test /Users/simen/Development/accelerator-core
> node scripts/test.js --env=jsdom "--dontWatch"

 PASS  src/components/App/App.test.tsx
  โœ“ Renders shallowly without crashing. (5ms)

Test Suites: 1 passed, 1 total
Tests:       1 passed, 1 total
Snapshots:   0 total
Time:        1.745s, estimated 2s
Ran all test suites.

Thank you for taking a look. The version (and results) you are seeing are for the master branch. The error is on the dev branch at https://github.com/furkleindustries/accelerator-core/tree/dev.

Ah right! ๐Ÿ˜…

I keep getting [Error: ENOENT: no such file or directory, open '/Users/simen/repos/accelerator-core/passages/passages-manifest.ts'], btw.

Beyond that though, your error is due to jest locating the wrong babel-jest. Either running npm dedupe will fix it, or this diff to your config:

diff --git i/config/testing/jest.config.js w/config/testing/jest.config.js
index 46bccb0..fb75f43 100644
--- i/config/testing/jest.config.js
+++ w/config/testing/jest.config.js
@@ -20,7 +20,7 @@ module.exports = {
   ],

   transform: {
-    '^.+\\.[jt]sx?$': 'babel-jest',
+    '^.+\\.[jt]sx?$': require.resolve('babel-jest'),
     '^.+\\.css$': '<rootDir>/config/testing/cssTransform.js',
     '^(?!.*\\.(js|jsx|ts|tsx|css|json)$)': '<rootDir>/config/testing/fileTransform.js',
   },

You can see babel-jest is not deduped by running npm ls babel-jest. Rerun that command after npm dedupe to see it's now deduped, and it works correctly

I'm almost positive that error is because the globalSetup wasn't being transpiled, and it is responsible for generating that file pre-testing. Anyway, this works perfectly! Thanks so much for your time.

globalSetup (and globalTeardown) is transpiled in Jest 24, fwiw ๐Ÿ™‚ But I doubt that's the reason, as jest would throw if globalSetup contained invalid syntax. Anyways, that's off topic, glad it worked for you!

Was this page helpful?
0 / 5 - 0 ratings