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

Tests failing only on WSL with 'Cannot find module' #203

Closed
bniedermeyer opened this issue Nov 27, 2018 · 9 comments
Closed

Tests failing only on WSL with 'Cannot find module' #203

bniedermeyer opened this issue Nov 27, 2018 · 9 comments

Comments

@bniedermeyer
Copy link

Suddenly when running jest in my Angular app within a WSL terminal tests are failing at random with a variation of Cannot find module or No such file error message pointing at my node_modules folder. Note: I ran npm install within the WSL work space so I don't believe it's an issue of incompatibility between windows and unix installs.
e.g.

# example of no such file error
ENOENT: no such file or directory, lstat '<root dir>/node_modules/tr46/lib/regexes.js'

      at Object.<anonymous> (node_modules/tr46/index.js:4:17)

# example of Cannot find module error
 Cannot find module '../start_of_week/index.js' from 'index.js'

      at Resolver.resolveModule (node_modules/jest-resolve/build/index.js:221:17)
      at Object.<anonymous> (node_modules/date-fns/start_of_iso_week/index.js:1:46)

I have not yet been able to find a pattern that is reproducible - the same tests aren't failing each time. To add even more confusion when I run my tests with my IDE (pointing to the same exact node_modules folder) everything works without issue - and the problem doesn't happen in our CI either. Here is the relevant sections of my package.json

"dependencies": {
    "@angular-devkit/core": "^0.7.5",
    "@angular-devkit/schematics": "^0.7.5",
    "@angular/animations": "6.1.3",
    "@angular/cdk": "^6.4.6",
    "@angular/cli": "6.1.4",
    "@angular/common": "6.1.3",
    "@angular/compiler": "6.1.3",
    "@angular/core": "6.1.3",
    "@angular/forms": "6.1.3",
    "@angular/http": "6.1.3",
    "@angular/platform-browser": "6.1.3",
    "@angular/platform-browser-dynamic": "6.1.3",
    "@angular/router": "6.1.3",
    "core-js": "^2.4.1",
    "date-fns": "^1.29.0",
    "normalize.css": "^7.0.0",
    "rxjs": "^6.2.2",
    "rxjs-compat": "^6.2.2",
    "zone.js": "^0.8.26"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~0.7.4",
    "@angular/compiler-cli": "6.1.3",
    "@angular/language-service": "6.1.3",
    "@angularclass/hmr": "^2.1.3",
    "@types/jest": "^23.3.2",
    "babel-preset-env": "^1.7.0",
    "codelyzer": "^4.3.0",
    "cz-conventional-changelog": "^2.1.0",
    "git-describe": "^4.0.3",
    "husky": "^0.14.3",
    "jasmine-marbles": "^0.3.1",
    "jest": "^23.5.0",
    "jest-preset-angular": "^6.0.0",
    "json-server": "^0.14.0",
    "lint-staged": "^7.2.0",
    "prettier": "^1.15.2",
    "protractor": "~5.1.2",
    "ts-node": "~3.2.0",
    "tslint": "~5.7.0",
    "tslint-angular": "^1.1.1",
    "tslint-config-prettier": "^1.12.0",
    "typescript": "2.9.2"
  },
@ahnpnl
Copy link
Collaborator

ahnpnl commented Dec 1, 2018

hi @bniedermeyer, have you tried to add those packages in your node_modules into the white list to ignore transforming by jest ? It is transformIgnorePatterns configuration from jest.

@bniedermeyer
Copy link
Author

@ahnpnl I have yes and still have the same issue. However the same commands work when run via my IDE's test commands (It's pointing at the same node_modules folder).

It's almost like it's a permissions issue within WSL but I can't find a culprit.

@ghost
Copy link

ghost commented Dec 18, 2018

I have the same issue. This is Windows problem..?

@bniedermeyer
Copy link
Author

@kazumeat It might be - but I haven't had time to look into it further. I found a workaround to call my tests via my IDE (using webstorm) and have been using that for now.

@bvitale
Copy link

bvitale commented Feb 11, 2019

I don't use jest-preset-angular but this ticket convinced me I wasn't crazy when I was getting these same random file not found errors.. when running Jest based tests on WSL.

I was able to resolve the issues with the latest Windows 10 updates. I think the root cause was this:
microsoft/WSL#2712
https://docs.microsoft.com/en-us/windows/wsl/release-notes (search for 2712)

Hope this helps someone else.

@csaxe
Copy link

csaxe commented Jun 12, 2019

I had the same issue; resolved when IT allowed me to upgrade my machine to 1903.

@bniedermeyer
Copy link
Author

Yeah - I think this is definitely an issue more on the WSL side vs a jest-preset-angular issue. I'm going to close this for now. FWIW if anyone runs across this later I found that if I don't have any processes (e.g my IDE) open to the directory my tests are in the chance for this random failure is much lower.

@csaxe
Copy link

csaxe commented Jun 12, 2019

A note that after an hour or more of searching, this was the first resource I found that addressed the same issue I was having, so this does seem a valuable resource for anyone working within an environment where they may not have access to latest Windows releases.

@ovgu12
Copy link

ovgu12 commented Oct 15, 2019

Thanks for reporting the issue as we are also having the issue while using jest with Vue. After trying to blame it for babel and co.. and googling to this thread i think we should upgrade to the latest Windows release.

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