jest: TypeError: _gracefulFs(...).realpathSync.native is not a function

Hi, I got this weird error, am I missing something ?

šŸ› Bug Report

When i try to run jest from the cli i got this error. Here is the complete traceback:

TypeError: _gracefulFs(...).realpathSync.native is not a function
    at tryRealpath (C:\Users\malau\Documents\ProjetJS\MOPJs\node_modules\jest-config\node_modules\jest-util\build\tryRealpath.js:26:39)
    at getCacheDirectory (C:\Users\malau\Documents\ProjetJS\MOPJs\node_modules\jest-config\build\getCacheDirectory.js:89:33)
    at Object.<anonymous> (C:\Users\malau\Documents\ProjetJS\MOPJs\node_modules\jest-config\build\Defaults.js:39:50)
    at Module._compile (module.js:653:30)
    at Object.Module._extensions..js (module.js:664:10)
    at Module.load (module.js:566:32)
    at tryModuleLoad (module.js:506:12)
    at Module.require (module.js:597:17)
    at require (internal/module.js:11:18)

To Reproduce

Steps to reproduce the behavior: npm install --save-dev jest jest-cli; npx jest --init or .\node_modules\.bin\jest --init Even just npx jest fail with the same error.

Link to repl or repo (highly encouraged)

My Project

envinfo

npx: installed 1 in 2.519s

  System:
    OS: Windows 10 10.0.18362
    CPU: (4) x64 Intel(R) Core(TM) i5-6300HQ CPU @ 2.30GHz
  Binaries:
    Node: 8.12.0 - C:\Program Files\nodejs\node.EXE
    npm: 6.4.1 - C:\Program Files\nodejs\npm.CMD
  npmPackages:
    jest: ^26.0.1 => 26.0.1

EDIT: With the latest version of node (14.2.0) it works without any issues.

Thank you in advance for your help !

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 8
  • Comments: 25 (3 by maintainers)

Commits related to this issue

Most upvoted comments

We do not support node 8, you need to upgrade to node 10 or keep using Jest 25 which supports node 8

Can we please drop this native junk

What a wonderfully productive way to ensure you get help with your issue

use basic standard library functions?

This is part of Node.js core

https://nodejs.org/api/fs.html#fs_fs_realpathsync_native_path_options

Sorry, but I’m not too clear on why this issue is closed. I’m running Mac OS Catalina, and have the same issue.

TypeError: _gracefulFs(...).realpathSync.native is not a function
    at tryRealpath (/Users/darrekt/Documents/forest-ranger/functions/node_modules/jest-util/build/tryRealpath.js:26:39)
    at getCacheDirectory (/Users/darrekt/Documents/forest-ranger/functions/node_modules/jest-config/build/getCacheDirectory.js:89:33)
    at Object.<anonymous> (/Users/darrekt/Documents/forest-ranger/functions/node_modules/jest-config/build/Defaults.js:39:50)
    at Module._compile (internal/modules/cjs/loader.js:1156:30)
    at Module._compile (pkg/prelude/bootstrap.js:1281:32)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1176:10)
    at Module.load (internal/modules/cjs/loader.js:1000:32)
    at Function.Module._load (internal/modules/cjs/loader.js:899:14)
    at Module.require (internal/modules/cjs/loader.js:1042:19)
    at Module.require (pkg/prelude/bootstrap.js:1225:31)

I’ve tried: Deleting, recloning and npm install my git repository. Each time, I delete package-lock.json and node_modules in their entirety. This seemed to fix an issue that was happening with fs during npm install…?

Anyway, the error still persisted, so I tried rolling back to Node.js 12.17.0 (was previously on 14). Same error occurs.

I tried completely removing node version manager and reinstalling Node, only to still find the same issue. I can’t find much help anywhere else online, so I thought I’d leave a comment here. The weirdest part is that it works on my older macbook which is running the same OS with the same version of node, installed with nvm. It also works on my Ubuntu workstation.

Here’s my envinfo and package.json, if it helps. This is the first time I’m reporting an issue, so do let me know if there’s anything else I can provide!

envinfo

    OS: macOS 10.15.4
    CPU: (8) x64 Intel(R) Core(TM) i5-1038NG7 CPU @ 2.00GHz
    Memory: 7.10 GB / 16.00 GB
    Shell: 5.7.1 - /bin/zsh
  Binaries:
    Node: 12.17.0 - ~/.nvm/versions/node/v12.17.0/bin/node
    npm: 6.14.4 - ~/.nvm/versions/node/v12.17.0/bin/npm
  Managers:
    Homebrew: 2.2.17 - /usr/local/bin/brew
    pip3: 20.1.1 - ~/.pyenv/shims/pip3
    RubyGems: 3.0.3 - /usr/bin/gem
  Utilities:
    Make: 3.81 - /usr/bin/make
    GCC: 4.2.1 - /usr/bin/gcc
    Git: 2.24.3 - /usr/bin/git
    Clang: 1103.0.32.62 - /usr/bin/clang
  Servers:
    Apache: 2.4.41 - /usr/sbin/apachectl
  IDEs:
    Nano: 2.0.6 - /usr/bin/nano
    VSCode: 1.45.1 - /usr/local/bin/code
    Vim: 8.1 - /usr/bin/vim
    Xcode: /undefined - /usr/bin/xcodebuild
  Languages:
    Bash: 3.2.57 - /bin/bash
    Java: 14.0.1 - /usr/bin/javac
    Perl: 5.18.4 - /usr/bin/perl
    PHP: 7.3.11 - /usr/bin/php
    Python: 3.7.7 - /Users/darrekt/.pyenv/shims/python
    Python3: 3.7.7 - /Users/darrekt/.pyenv/shims/python3
    Ruby: 2.6.3 - /usr/bin/ruby
  Databases:
    PostgreSQL: 12.3 - /usr/local/bin/postgres
    SQLite: 3.28.0 - /usr/bin/sqlite3
  Browsers:
    Chrome: 83.0.4103.61
    Safari: 13.1

package.json

{
  "name": "functions",
  "scripts": {
    "start": "concurrently -n tsc,firebase \"npm run watch\" \"firebase emulators:start --only firestore,functions\"",
    "test": "npm run build && firebase emulators:exec --only firestore,functions jest",
    "test-debug": "node --inspect-brk node_modules/.bin/jest --runInBand",
    "build": "tsc",
    "watch": "tsc --watch",
    "lint": "tslint --project tsconfig.json",
    "shell": "npm run build && firebase functions:shell",
    "deploy": "firebase deploy --only functions",
    "logs": "firebase functions:log"
  },
  "engines": {
    "node": "10"
  },
  "jest": {
    "testEnvironment": "jest-environment-uint8array"
  },
  "main": "lib/index.js",
  "dependencies": {
    "express": "^4.17.1",
    "firebase-admin": "^8.10.0",
    "firebase-functions": "^3.6.1"
  },
  "devDependencies": {
    "@firebase/testing": "^0.19.4",
    "@types/express": "^4.17.6",
    "concurrently": "^5.2.0",
    "copyfiles": "^2.2.0",
    "firebase": "^7.14.4",
    "firebase-functions-test": "^0.2.0",
    "jest": "^26.0.1",
    "jest-environment-uint8array": "^1.0.0",
    "tslint": "^5.12.0",
    "typescript": "^3.8.0"
  },
  "private": true
}

We do not support node 8, you need to upgrade to node 10 or keep using Jest 25 which supports node 8

i updated to 12, still having the same error. do i need to stay at exactly 10?

I got the same error with Jest but my cause was because of the node version i was using…I upgraded from 8.16 to the latest version 12 and the error disappeared.Sounds like older versions of node are slowly becoming deprecated while using Jest

The same for me, I updated to node 14.6.0, running the jest is ok, when debugging the jest, I got the same error

TypeError: _gracefulFs(...).realpathSync.native is not a function
    at tryRealpath (/Users/chenliang/Desktop/partice/vue-next/node_modules/jest-util/build/tryRealpath.js:26:39)
    at getCacheDirectory (/Users/chenliang/Desktop/partice/vue-next/node_modules/jest-config/build/getCacheDirectory.js:89:33)
    at Object.<anonymous> (/Users/chenliang/Desktop/partice/vue-next/node_modules/jest-config/build/Defaults.js:39:50)
    at Module._compile (module.js:653:30)
    at Object.Module._extensions..js (module.js:664:10)
    at Module.load (module.js:566:32)
    at tryModuleLoad (module.js:506:12)
    at Function.Module._load (module.js:498:3)
    at Module.require (module.js:597:17)
    at require (internal/module.js:11:18)

Confirm the problem. If it relates to the node version my node is 10.15.0.

Easiest way to re-install dependencies after upgrading Node version to 10+ is to remove node_modules and package-lock.json. Just type yarn or npm i from there šŸ˜„