Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot read property 'Component' of undefined #659

Closed
diegoddox opened this issue Aug 5, 2018 · 5 comments
Closed

Cannot read property 'Component' of undefined #659

diegoddox opened this issue Aug 5, 2018 · 5 comments

Comments

@diegoddox
Copy link

I'm facing the same issue as #146
Error.
TypeError: Cannot read property 'Component' of undefined

package.json

...
"ts-jest": "^23.0.1",
"jest": "^23.4.2",
"babel-jest": "^23.4.2",
"babel-preset-react-native": "^4.0.0",
"typescript": "^2.9.2"
...
"jest": {
    "preset": "react-native",
    "setupFiles": [
      "./setupJest.js"
    ],
    "transformIgnorePatterns": [
      "node_modules/(?!(jest-)?react-native|react-navigation)"
    ],
    "testPathIgnorePatterns": [
      "build",
      "tests",
      "node_modules/"
    ],
    "cacheDirectory": ".jest/cache",
    "transform": {
      "^.+\\.js$": "babel-jest",
      ".+\\.(css|png)$": "jest-transform-stub",
      "^.+\\.tsx?$": "ts-jest"
    },
    "testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$",
    "moduleDirectories": [
      "node_modules",
      "src"
    ],
    "moduleFileExtensions": [
      "ts",
      "js",
      "jsx",
      "tsx",
      "json",
      "node"
    ],
    "globals": {
      "ts-jest": {
        "useBabelrc": true
      },
      "__TS_CONFIG__": {
        "module": "esnext"
      }
    }
  }

tsconfig.json

...
"module": "esnext",
"allowSyntheticDefaultImports": true,
...

Any idea on how can I fix this?

@huafu
Copy link
Collaborator

huafu commented Aug 5, 2018

@diegoddox thanks for reporting the issue.

Can you try this:

// package.json - jest:
    "globals": {
      "ts-jest": {
        "tsConfigFile": "tsconfig.test.json"
      }
    }

and in tsconfig.test.json:

{
  "extends": "tsconfig.json",
  "compilerOptions": {
    "esModuleInterop": true
  }
}

If that doesn't work, please provide a minimal repo to reproduce the issue.

FYI, the __TS_CONFIG__ does nothing, it has been removed quite some time ago.

@diegoddox
Copy link
Author

Thanks @huafu

@tonoslav
Copy link

tonoslav commented Nov 7, 2018

instead of "tsConfigFile" use "tsConfig" (not error)

@chuntley
Copy link

In tsconfig.test.json, make sure you include a path for extends:

{
  "extends": "./tsconfig.json",
  "compilerOptions": {
    "esModuleInterop": true
  }
}

@the-homeless-god
Copy link

the-homeless-god commented Jul 17, 2023

be sure that now you need define it under transform section like the following

jest.config.js

module.exports = {
  ...,
   transform: {
        '^.+\\.(ts|tsx)?$': [
            'ts-jest',
            {
                isolatedModules: true,
                tsconfig: 'tsconfig.test.json',
            },
        ],
    },
  ...
}

Because

ts-jest[ts-jest-transformer] (WARN) Define `ts-jest` config under `globals` is deprecated. 

Please do
transform: {
    <transform_regex>: ['ts-jest', { /* ts-jest config goes here in Jest */ }],
},

ts-jest[backports]
(WARN) "[jest-config].globals.ts-jest.tsConfigFile" is deprecated, use "[jest-config].globals.ts-jest.tsconfig" instead.

ts-jest[backports]
(WARN) Your Jest configuration is outdated. Use the CLI to help migrating it: ts-jest config:migrate <config-file>.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants