jestjs / jest

Delightful JavaScript Testing.
https://jestjs.io
MIT License
44.07k stars 6.44k forks source link

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

Closed MalauD closed 4 years ago

MalauD commented 4 years ago

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 !

SimenB commented 4 years ago

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

mcandre commented 4 years ago

I get the same error in Node.js 12. Can we please drop this native junk and use basic standard library functions?

SimenB commented 4 years ago

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

gdubs commented 4 years ago

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?

thymikee commented 4 years ago

@gdubs you can use whatever version since 10.14.2. Make sure you re-install your deps to update native bindings when changing Node versions

dginovker commented 4 years ago

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 :smile:

Darrekt commented 4 years ago

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
}
dedanmsafari commented 4 years ago

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

konstantin-tarasov-clearscale commented 4 years ago

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

LiorRacer commented 4 years ago

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

The same for me, I upgraded to node 13.12.0 from 10.15.0 and it solve it

SimenB commented 4 years ago

Node 10.15.0 has realpathSync.native, as does graceful-fs when required.

// file.js
console.log(process.version);
console.log(typeof require('fs').realpathSync.native);
console.log(typeof require('graceful-fs').realpathSync.native);
$ node file.js
v10.15.0
function
function

If anyone can provide a reproduction that fails on Node 10.15 I'm happy to take a look. Something we can clone, run install, run jest and see the error.

A really reduced example would be calling the function that throws, e.g.

'use strict';

const {tryRealpath} = require('jest-util');

// enter some absolute path of a file that exists
console.log(tryRealpath('/some/absolute/path'));

That's the function that throws in the stack traces posted in this issue

liang520 commented 4 years ago

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)
djedjethai commented 4 years ago

Updating from node v8 to node v12.18.2, worked for me. Thanks.

njyrbecker commented 4 years ago

node v12.13.1 is not working for me - same error.

liang520 commented 4 years ago

Updating from node v8 to node v12.18.2, worked for me. Thanks.

@djedjethai is working for debugging?

djedjethai commented 4 years ago

I use it to run my tests when i push my code to github.

damaon commented 4 years ago

Failing on v10.15.3 for me with jest 26.2.0 (fixed when switched to ^25)

RaviH commented 4 years ago

Hello,

It seems like issue is still happening on Travis CI:

$ node --version
v12.18.3
$ npm --version
6.14.6
$ nvm --version
0.35.3
$ yarn --version
1.22.4
before_install.1
8.52s$ curl -sL https://firebase.tools | bash
before_install.2
0.00s$ export PATH="$HOME/.yarn/bin:$PATH"
install
1.10s$ yarn --frozen-lockfile
1.14s$ yarn install
yarn install v1.22.4
[1/5] Validating package.json...
[2/5] Resolving packages...
success Already up-to-date.
The command "yarn install" exited with 0.
11.75s$ firebase emulators:exec --only firestore './functional-test-setup.sh'
⚠  emulators: You are not currently authenticated so some features may not work correctly. Please run firebase login to authenticate the CLI.
i  emulators: Starting emulators: firestore
⚠  It appears you are running in a CI environment. You can avoid downloading the Firestore Emulator repeatedly by caching the /home/travis/.cache/firebase/emulators directory.
i  firestore: downloading cloud-firestore-emulator-v1.11.7.jar...
- (55% of 64MB)i  firestore: Firestore Emulator logging to firestore-debug.log
i  Running script: ./functional-test-setup.sh
Starting tests!
yarn run v1.22.4
$ jest --env=jest-environment-jsdom-sixteen --runInBand --coverage=true
TypeError: _gracefulFs(...).realpathSync.native is not a function
    at tryRealpath (/home/travis/build/RaviH/radiology-cored/node_modules/jest-util/build/tryRealpath.js:26:39)
    at getCacheDirectory (/home/travis/build/RaviH/radiology-cored/node_modules/jest-cli/node_modules/jest-config/build/getCacheDirectory.js:89:33)
    at Object.<anonymous> (/home/travis/build/RaviH/radiology-cored/node_modules/jest-cli/node_modules/jest-config/build/Defaults.js:49:50)
    at Module._compile (internal/modules/cjs/loader.js:1136:30)
    at Module._compile (pkg/prelude/bootstrap.js:1281:32)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1156:10)
    at Module.load (internal/modules/cjs/loader.js:984:32)
    at Function.Module._load (internal/modules/cjs/loader.js:877:14)
    at Module.require (internal/modules/cjs/loader.js:1024:19)
    at Module.require (pkg/prelude/bootstrap.js:1225:31)
error Command failed with exit code 1.
lukasknutti commented 4 years ago

I encounter the same issue running my tests in the firebase emulator. Using node 12.18 (running it on my machine outside of the emulator works fine)

i  functions[userCreated]: function ignored because the auth emulator does not exist or is not running.
i  functions[userDeleted]: function ignored because the auth emulator does not exist or is not running.
i  Running script: npm test

> functions@ test /Users/lukasknutti/Desktop/programming/th-firebase/functions
> jest --watchAll --verbose=true

TypeError: _gracefulFs(...).realpathSync.native is not a function
    at tryRealpath (/Users/lukasknutti/Desktop/programming/th-firebase/functions/node_modules/jest-util/build/tryRealpath.js:26:39)
    at getCacheDirectory (/Users/lukasknutti/Desktop/programming/th-firebase/functions/node_modules/jest-config/build/getCacheDirectory.js:89:33)
    at Object.<anonymous> (/Users/lukasknutti/Desktop/programming/th-firebase/functions/node_modules/jest-config/build/Defaults.js:49:50)
    at Module._compile (internal/modules/cjs/loader.js:1136:30)
    at Module._compile (pkg/prelude/bootstrap.js:1281:32)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1156:10)
    at Module.load (internal/modules/cjs/loader.js:984:32)
    at Function.Module._load (internal/modules/cjs/loader.js:877:14)
    at Module.require (internal/modules/cjs/loader.js:1024:19)
    at Module.require (pkg/prelude/bootstrap.js:1225:31)
npm ERR! Test failed.  See above for more details.
⚠  Script exited unsuccessfully (code 1)
i  emulators: Shutting down emulators.
levnach commented 3 years ago

When I run jest from ubuntu terminal it works fine. However if I run it from emacs shell I get an error TypeError: _gracefulFs(...).realpathSync.native is not a function at tryRealpath (/home/lev/dev/jsagl/node_modules/jest-util/build/tryRealpath.js:26:39) at getCacheDirectory (/home/lev/dev/jsagl/node_modules/jest-config/build/getCacheDirectory.js:89:33) at Object. (/home/lev/dev/jsagl/node_modules/jest-config/build/Defaults.js:39:50) at Module._compile (module.js:652:30) at Object.Module._extensions..js (module.js:663:10) at Module.load (module.js:565:32) at tryModuleLoad (module.js:505:12) at Function.Module._load (module.js:497:3) at Module.require (module.js:596:17) at require (internal/module.js:11:18) npm ERR! Test failed. See above for more details.

Adding the node version info: lev@lev-SLaptop:~$ node --version v14.15.1

caelinsutch commented 3 years ago

@lukasknutti Did you ever figure this out? Having the same issue

levnach commented 3 years ago

Yes, I figured it out. I was running an old version of node in this scenario.

msichterman commented 3 years ago

I encounter the same issue running my tests in the firebase emulator. Using node 12.18 (running it on my machine outside of the emulator works fine)

i  functions[userCreated]: function ignored because the auth emulator does not exist or is not running.
i  functions[userDeleted]: function ignored because the auth emulator does not exist or is not running.
i  Running script: npm test

> functions@ test /Users/lukasknutti/Desktop/programming/th-firebase/functions
> jest --watchAll --verbose=true

TypeError: _gracefulFs(...).realpathSync.native is not a function
    at tryRealpath (/Users/lukasknutti/Desktop/programming/th-firebase/functions/node_modules/jest-util/build/tryRealpath.js:26:39)
    at getCacheDirectory (/Users/lukasknutti/Desktop/programming/th-firebase/functions/node_modules/jest-config/build/getCacheDirectory.js:89:33)
    at Object.<anonymous> (/Users/lukasknutti/Desktop/programming/th-firebase/functions/node_modules/jest-config/build/Defaults.js:49:50)
    at Module._compile (internal/modules/cjs/loader.js:1136:30)
    at Module._compile (pkg/prelude/bootstrap.js:1281:32)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1156:10)
    at Module.load (internal/modules/cjs/loader.js:984:32)
    at Function.Module._load (internal/modules/cjs/loader.js:877:14)
    at Module.require (internal/modules/cjs/loader.js:1024:19)
    at Module.require (pkg/prelude/bootstrap.js:1225:31)
npm ERR! Test failed.  See above for more details.
⚠  Script exited unsuccessfully (code 1)
i  emulators: Shutting down emulators.

@lukasknutti did you ever figure this out?

lukasknutti commented 3 years ago

I encounter the same issue running my tests in the firebase emulator. Using node 12.18 (running it on my machine outside of the emulator works fine)

i  functions[userCreated]: function ignored because the auth emulator does not exist or is not running.
i  functions[userDeleted]: function ignored because the auth emulator does not exist or is not running.
i  Running script: npm test

> functions@ test /Users/lukasknutti/Desktop/programming/th-firebase/functions
> jest --watchAll --verbose=true

TypeError: _gracefulFs(...).realpathSync.native is not a function
    at tryRealpath (/Users/lukasknutti/Desktop/programming/th-firebase/functions/node_modules/jest-util/build/tryRealpath.js:26:39)
    at getCacheDirectory (/Users/lukasknutti/Desktop/programming/th-firebase/functions/node_modules/jest-config/build/getCacheDirectory.js:89:33)
    at Object.<anonymous> (/Users/lukasknutti/Desktop/programming/th-firebase/functions/node_modules/jest-config/build/Defaults.js:49:50)
    at Module._compile (internal/modules/cjs/loader.js:1136:30)
    at Module._compile (pkg/prelude/bootstrap.js:1281:32)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1156:10)
    at Module.load (internal/modules/cjs/loader.js:984:32)
    at Function.Module._load (internal/modules/cjs/loader.js:877:14)
    at Module.require (internal/modules/cjs/loader.js:1024:19)
    at Module.require (pkg/prelude/bootstrap.js:1225:31)
npm ERR! Test failed.  See above for more details.
⚠  Script exited unsuccessfully (code 1)
i  emulators: Shutting down emulators.

@lukasknutti did you ever figure this out?

yes, this solved my problem -> https://stackoverflow.com/questions/63577475/firebase-cloud-function-unit-test-http-oncall/63591428#63591428

github-actions[bot] commented 3 years ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.