Skip to content

TypeError: Cannot read property 'options' of undefined #267

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

Closed
gem007bd opened this issue Aug 12, 2020 · 15 comments
Closed

TypeError: Cannot read property 'options' of undefined #267

gem007bd opened this issue Aug 12, 2020 · 15 comments
Labels
jest 27 upstream Due to other packages (like Jest) vue3-jest Vue 3

Comments

@gem007bd
Copy link

gem007bd commented Aug 12, 2020

I am facing this error even for the simple test case with the latest version. I am trying to update vue2 to vue3
I am using:
"vue": "^3.0.0-rc.5",
"vuex": "^4.0.0-beta.4",
"vue-jest": "^5.0.0-alpha.3",
"@vue/test-utils": "^2.0.0-beta.2"

Test suite failed to run

TypeError: Cannot read property 'options' of undefined

  at getTsJestConfig (node_modules/vue-jest/lib/utils.js:71:45)
  at processTemplate (node_modules/vue-jest/lib/process.js:73:20)
  at Object.module.exports [as process] (node_modules/vue-jest/lib/process.js:107:26)
  at ScriptTransformer.transformSource (node_modules/@jest/transform/build/ScriptTransformer.js:463:35)
  at ScriptTransformer._transformAndBuildScript (node_modules/@jest/transform/build/ScriptTransformer.js:568:40)
  at ScriptTransformer.transform (node_modules/@jest/transform/build/ScriptTransformer.js:606:25)
@PeckZeg
Copy link

PeckZeg commented Aug 12, 2020

I found vue-jest@next use ts-jest^24.0.0, I guess you use ts-jest latest version.

you can put ts-jest, jest, @types/jest back to 24.x.

yarn add @types/jest^24.9.1 jest^24.9.0 ts-jest^24.3.0 --dev --force

@gem007bd
Copy link
Author

gem007bd commented Aug 13, 2020

@PeckZeg should I need to downgrade '@vue/test-utils' version also?
I am using "^2.0.0-beta.2"

@PeckZeg
Copy link

PeckZeg commented Aug 14, 2020

@PeckZeg should I need to downgrade '@vue/test-utils' version also?
I am using "^2.0.0-beta.2"

no need. all beta version has this problem

@lmiller1990
Copy link
Member

lmiller1990 commented Aug 16, 2020

I have your exact dependencies and it's working fine for me. Did you get this working with the latest ts-jest?

Can you provide a repo with this not working? Vue CLI should have this working out of the box.

Fwiw I do not expect upgrading projects from Vue 2 to Vue 3 to be easy - VTU v2 is usable but still in it's early days and there are likely some undocumented behaviors many libraries came to rely on that have not been ported.

@shortpoet
Copy link

Got same error. Switched back to ts-jest^24.0.0 as suggested and it works again. Here is stack trace.

TypeError: Cannot read property 'options' of undefined

  at getTsJestConfig (node_modules/vue-jest/lib/utils.js:71:45)
  at processTemplate (node_modules/vue-jest/lib/process.js:73:20)
  at Object.module.exports [as process] (node_modules/vue-jest/lib/process.js:107:26)
  at ScriptTransformer.transformSource (C:/Users/shortpoet/AppData/Local/Yarn/Data/global/node_modules/@jest/transform/build/ScriptTransformer.js:463:35)
  at ScriptTransformer._transformAndBuildScript (C:/Users/shortpoet/AppData/Local/Yarn/Data/global/node_modules/@jest/transform/build/ScriptTransformer.js:568:40)
  at ScriptTransformer.transform (C:/Users/shortpoet/AppData/Local/Yarn/Data/global/node_modules/@jest/transform/build/ScriptTransformer.js:606:25)

When I try looking at the undefined object, it seems like the typescript key is undefined. It isn't even defined in the type definition for the createTransformer that calls it.

  • vue-jest/lib/utils.js
  const createTransformer = require('ts-jest').createTransformer
  const tr = createTransformer()
  const { typescript } = tr.configsFor(config)
  // Force es5 to prevent const vue_1 = require('vue') from conflicting
  return { compilerOptions: { ...typescript.options, target: 'es5' } }

When you try and log the same object from a version that does work, it doesn't even get called. Seems to be looking for some typescript config file/key out of the jest.config.

That's about all I was able to garner, hope it helps a bit.

@lmiller1990
Copy link
Member

lmiller1990 commented Aug 16, 2020

I pulled this branch of my course https://github.com/lmiller1990/vuejs-composition-course/tree/1.3-reactive-updates-using-ref, ran yarn install and then ran yarn jest and it works. How are you guys creating your projects? Can someone post a reproduction? Issues with vue-jest are often a combination of libraries.

{
  "name": "vtu-next-demo",
  "version": "1.0.0",
  "main": "index.js",
  "license": "MIT",
  "scripts": {
    "test": "yarn jest",
    "dev": "yarn webpack-dev-server",
    "build": "yarn webpack --mode production"
  },
  "devDependencies": {
    "@babel/node": "^7.8.7",
    "@babel/preset-env": "^7.9.0",
    "@types/highlight.js": "^9.12.3",
    "@types/jest": "^25.2.1",
    "@types/lodash": "^4.14.150",
    "@types/marked": "^0.7.4",
    "@types/moment": "^2.13.0",
    "@vue/compiler-sfc": "^3.0.0-beta.4",
    "@vue/test-utils": "^2.0.0-alpha.6",
    "babel-jest": "^25.2.6",
    "clean-webpack-plugin": "^3.0.0",
    "css-loader": "^3.5.3",
    "flush-promises": "^1.0.2",
    "identity-obj-proxy": "^3.0.0",
    "jest": "^25.2.7",
    "ts-jest": "^25.3.1",
    "ts-loader": "^6.2.2",
    "typescript": "^3.8.3",
    "vue-jest": "^5.0.0-alpha.0",
    "vue-loader": "^16.0.0-alpha.3"
  },
  "dependencies": {
    "axios": "^0.19.2",
    "highlight.js": "^10.0.2",
    "lodash": "^4.17.15",
    "marked": "^1.0.0",
    "moment": "^2.24.0",
    "vue": "^3.0.0-rc.5",
    "vue-router": "^4.0.0-alpha.13"
  }
}

@lmiller1990
Copy link
Member

@shortpoet I see the error - how can I reproduce this? How did set this up? Vue CLI, another template, by yourself? Can you post a minimal repo? Using Vue + Jest + TS requires many different libraries to all "work" together, maybe we need to document which version(s) of things to use. Ideally we should just use the latest stable version for everything, which I think is TS 3.x, Jest 25.x or 26.x.

@gem007bd
Copy link
Author

Hello @lmiller1990 you will find the error in this repo.

https://github.com/gem007bd/vue3-jest-playground

@lmiller1990
Copy link
Member

@gem007bd your ts-jest and jest versions are different. You have Jest 26.4.x and ts-jest is 26.2. You should always use the ts-jest version matching jest. I did yarn add [email protected] [email protected] (latest ts-jest is 26.2.0) and did yarn jest and it worked.

@lmiller1990
Copy link
Member

lmiller1990 commented Aug 25, 2020

@shortpoet/Carlos can you repro the error w/ matching ts-jest and jest? Seem this is the "bug" - not having the correct versions.

@djytwy
Copy link

djytwy commented Sep 17, 2020

when i use npm this problem is no occur

@Vicula
Copy link

Vicula commented Jun 14, 2021

https://github.com/Vicula/vue-tsx

FAIL src/vue/utilities/test.spec.ts
● Test suite failed to run

TypeError: Cannot destructure property 'config' of 'undefined' as it is undefined.

  at Object.getCacheKey (node_modules/vue-jest/lib/index.js:10:7)

I can reproduce the above issue still. @lmiller1990

Using vue 3 single file component setup with TSX for render function.

Having problem running jest tests and getting same above error.

"dependencies": {
   "vue": "^3.0.5"
 },
 "devDependencies": {
   "@types/jest": "^26.0.23",
   "@types/node": "^14.14.22",
   "@types/react": "^17.0.9",
   "@typescript-eslint/eslint-plugin": "^4.15.0",
   "@typescript-eslint/parser": "^4.15.0",
   "@vitejs/plugin-vue": "^1.1.4",
   "@vitejs/plugin-vue-jsx": "^1.1.0",
   "@vue/compiler-sfc": "^3.0.5",
   "@vue/eslint-config-prettier": "^6.0.0",
   "@vue/eslint-config-typescript": "^7.0.0",
   "@vue/test-utils": "^2.0.0-rc.6",
   "@vuedx/typecheck": "^0.6.0",
   "@vuedx/typescript-plugin-vue": "^0.6.0",
   "chalk": "^4.1.1",
   "cypress": "^7.5.0",
   "eslint": "^7.19.0",
   "eslint-plugin-cypress": "^2.11.3",
   "eslint-plugin-prettier": "^3.1.0",
   "eslint-plugin-vue": "^7.5.0",
   "husky": "^5.0.9",
   "jest": "^27.0.0-next.12",
   "lint-staged": "^10.5.4",
   "prettier": "^2.2.1",
   "sass": "^1.34.1",
   "start-server-and-test": "^1.12.5",
   "stylelint": "^13.9.0",
   "stylelint-config-recommended": "^3.0.0",
   "stylelint-config-standard": "^20.0.0",
   "ts-jest": "^27.0.0-next.12",
   "typescript": "^4.1.3",
   "vite": "^2.0.0-beta.65",
   "vue-jest": "^5.0.0-alpha.10"
 }

@Vicula
Copy link

Vicula commented Jun 14, 2021

Property 'getCacheKey' does not exist on type 'typeof import("/node_modules/babel-jest/build/index")'.

@lmiller1990
Copy link
Member

Can you try using Jest 26? You have Jest 27 - it has breaking changes. A similar issue.

We are working on Jest 27 support here: #343

@nogic1008
Copy link
Collaborator

@vue/vue2-jest and @vue/vue3-jest have been released.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
jest 27 upstream Due to other packages (like Jest) vue3-jest Vue 3
Projects
None yet
Development

No branches or pull requests

7 participants