question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Tests failing only on WSL with 'Cannot find module'

See original GitHub issue

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"
  },

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:9

github_iconTop GitHub Comments

2reactions
csaxecommented, Jun 12, 2019

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

2reactions
bvitalecommented, 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: https://github.com/Microsoft/WSL/issues/2712 https://docs.microsoft.com/en-us/windows/wsl/release-notes (search for 2712)

Hope this helps someone else.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Troubleshooting Windows Subsystem for Linux | Microsoft Learn
Provides detailed information about common errors and issues people run into while running Linux on the Windows Subsystem for Linux.
Read more >
How do I resolve "Cannot find module" error using Node.js?
Using npm install installs the module into the current directory only (in a subdirectory called node_modules ). Is app.js located under ...
Read more >
TypeScript Service fail to start under WSL (2) because it ...
TypeScript Service fail to start under WSL (2) because it expects mounts under /mnt/ ... TypeScript service fials to launch with Cannot find...
Read more >
cypress-io/cypress - Gitter
Hey everyone - I'm trying to use Vue and the experimental component testing in Cypress. Has anyone had experience with testing for custom...
Read more >
Python testing in Visual Studio Code
Because the test failure can easily be traced to a particular code change, it's easy to find and remedy the cause of the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found