Skip to content
This repository has been archived by the owner on Jan 26, 2019. It is now read-only.

Test fails during set-up with TypeScript 2.6.X #198

Open
karak opened this issue Nov 28, 2017 · 5 comments
Open

Test fails during set-up with TypeScript 2.6.X #198

karak opened this issue Nov 28, 2017 · 5 comments

Comments

@karak
Copy link

karak commented Nov 28, 2017

Is this a bug report?

Yes

Can you also reproduce the problem with npm 4.x?

No for npm 4.6.1 nor 5.5.1, but yes for all after installing by yarn.

Which terms did you search for in User Guide?

'jest' and 'ts-jest'

Environment

  1. node -v: v8.9.0
  2. npm -v:5.5.1
  3. yarn --version (if you use Yarn): 1.2.1
  4. npm ls react-scripts-ts (if you haven’t ejected):
    [email protected] /Users/XXXX/XXXXX
    └── UNMET DEPENDENCY [email protected]
    npm ERR! missing: [email protected], required by [email protected]

macOS High Sierra

Steps to Reproduce

  1. Created project with create-react-app --scripts-version=react-scripts-ts
  2. Upgrade typescript with yarn add typescript@^2.6.0
  3. Run tests yarn test and press [A] to fail in module resolution.
 FAIL  src/App.test.tsx
  ● Test suite failed to run

    Cannot find module 'ts-jest' from 'App.test.tsx'

      at Resolver.resolveModule (node_modules/jest-resolve/build/index.js:179:17)
      at Object.<anonymous> (src/App.test.tsx:1:103)

It never happens in case of yarn add [email protected], same as dependent one of react-scripts-ts.

Expected Behavior

Execute test codes successfully.

Actual Behavior

Fails before actual tests.

Reproducible Demo

https://github.com/karak/ts-jest-error.git

@DorianGrey
Copy link
Collaborator

This one is extremely weird - when installing via yarn, ts-jest does not seem to be installed in the root directory.

ls node_modules | grep ts-jest | wc -l
0

Finally found it in the react-scripts-ts directory:

ls node_modules/react-scripts-ts/node_modules | grep ts-jest | wc -l 
1

When installing via npm, it gets installed in the root's node_modules.

ls node_modules | grep ts-jest | wc -l
1

Seems that's why it cannot be found. I'll see if I can figure out where this difference comes from ...

For the moment, manually executing yarn add --dev ts-jest will work this issue.

@karak
Copy link
Author

karak commented Nov 28, 2017

@DorianGrey Thank you for you work.

After all, our real code sometimes didn't work by manual installing, probably depending on the installation order, but thanks anyway.

Yes, it's extraordinally weird even though yarn has known troubles around nested dependency I know.

I hope #181 and/or #191 will resolve this.

@karak
Copy link
Author

karak commented Jan 23, 2018

I'm testing this issue since fixing release of #181, but I wasn't able to reproduce the original behavior before this.

The versions of node and npm are same. yarn is now changed to 1.3.2.

My procedure is:

  1. create-react-app [email protected] ts-jest-error-2.8.0
  2. cd ts-jest-error-2.8.0/
  3. yarn install
  4. yarn add [email protected] *changed because 2.6.0 is initially assigned
  5. yarn test

Any advice?

@smifun
Copy link

smifun commented Mar 22, 2018

I got same issues after react-scripts-ts upgrade from 2.8.0 to 2.14.0, I fix it by installing jest & ts-jest as dev dependency.

➜  customer-portal git:(feature/CYB-410-ui-lib-upgrade) ✗ find . -name 'jest' -type d
./node_modules/@types/jest
./node_modules/jest
./node_modules/react-scripts-ts/config/jest
./node_modules/react-scripts-ts/node_modules/jest
➜  customer-portal git:(feature/CYB-410-ui-lib-upgrade) ✗ find . -name 'ts-jest' -type d
./node_modules/react-scripts-ts/node_modules/ts-jest
./node_modules/ts-jest

@tyson-kubota
Copy link

I ran into this Cannot find module 'ts-jest' from 'App.test.tsx' breakage after clearing and reinstalling my node_modules. (I was on "react-scripts-ts": "^2.13.0" at the time, using an unejected app). I had to manually update to [email protected] to get Jest tests working again. Apparently, Jest below ~22.x has some issues, as noted #255.

It's not clear to me why Jest worked on first creating this (very simple app), then broke after clearing and reinstalling my node_modules (my only test was the default App.test.tsx one)... but after upgrading react-scripts-ts, tests were runnable again.

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

No branches or pull requests

4 participants