React Native + Jest EMFILE:打开文件过多错误 [英] React Native + Jest EMFILE: too many open files error

查看:106
本文介绍了React Native + Jest EMFILE:打开文件过多错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试运行Jest测试,但出现以下错误:

I am trying to run Jest tests, but I'm getting the following error:

读取文件时出错:/Users/mike/dev/react/TestTest/node_modules/react-native/node_modules/yeoman-environment/node_modules/globby/node_modules/glob/node_modules/path-is-absolute/package.json /Users/mike/dev/react/TestTest/node_modules/jest-cli/node_modules/node-haste/lib/loader/ResourceLoader.js:88 抛出错误; ^

Error reading file: /Users/mike/dev/react/TestTest/node_modules/react-native/node_modules/yeoman-environment/node_modules/globby/node_modules/glob/node_modules/path-is-absolute/package.json /Users/mike/dev/react/TestTest/node_modules/jest-cli/node_modules/node-haste/lib/loader/ResourceLoader.js:88 throw err; ^

错误:EMFILE:打开的文件太多,打开'/Users/mike/dev/react/TestTest/node_modules/react-native/node_modules/yeoman-environment/node_modules/globby/node_modules/glob/node_modules/path-is -absolute/package.json' 错误时(本机) npm ERR!测试失败.有关更多详细信息,请参见上文.

Error: EMFILE: too many open files, open '/Users/mike/dev/react/TestTest/node_modules/react-native/node_modules/yeoman-environment/node_modules/globby/node_modules/glob/node_modules/path-is-absolute/package.json' at Error (native) npm ERR! Test failed. See above for more details.

对我来说有趣的是,错误中列出的路径指向node_modules目录中的文件,由于testPathIgnorePatterns中的node_modules条目,我希望不会读取该文件.

What is interesting to me is that the path listed in the error points to a file in the node_modules directory, which I expected would not be read because of the node_modules entry in testPathIgnorePatterns.

我正在运行Node 4.2.1,我的React-Native安装只有一个星期的时间,我今天安装了Jest(所以我认为我掌握了所有最新信息).我在Mac上.

I'm running Node 4.2.1, my install of React-Native is only a week old, I installed Jest today (so I think I'm up to date with everything). I'm on a Mac.

我已经运行:sudo ulimit -n 10240,关闭了所有终端窗口,甚至尝试重新启动. (在我的.bash_profile中,我以前添加了ulimit -n 1024.而且我尝试了更大的数字.

I have run: sudo ulimit -n 10240, closed all Terminal windows, and even tried a reboot. (In my .bash_profile I had previously added ulimit -n 1024. And I've tried even larger numbers.

为确保问题不仅出在我自己的项目中,我用react-native init TestTest创建了一个新项目,并建议RN对package.json进行建议更改:

To make sure the problem is not just in my own project, I created a new project with react-native init TestTest and made RN's suggested changes to the package.json:

{
  "name": "TestTest",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "start": "node_modules/react-native/packager/packager.sh",
    "test": "jest"
  },
  "dependencies": {
    "react-native": "^0.14.1"
  },
  "jest": {
    "scriptPreprocessor": "node_modules/react-native/jestSupport/scriptPreprocess.js",
    "setupEnvScriptFile": "node_modules/react-native/jestSupport/env.js",
    "testPathIgnorePatterns": [
      "/node_modules/",
      "packager/react-packager/src/Activity/"
    ],
    "testFileExtensions": [
      "js"
    ],
    "unmockedModulePathPatterns": [
      "promise",
      "source-map"
    ]
  },
  "devDependencies": {
    "jest-cli": "^0.7.1"
  }
}

但是我每次都会遇到相同的错误.

But I'm getting the same error every time.

推荐答案

简短的答案:在〜.bash_profile中添加'ulimit -n 4096'并打开一个新的终端窗口解决了我的问题.

Short answer: adding 'ulimit -n 4096' to ~.bash_profile and opening a new terminal window resolved my issue.

答案与我有关,不能正确设置ulimit.

The answer had to do with me not setting the ulimit properly.

sudo ulimit -n 10240

我的Mac上的

不会更改ulimit.我原本以为它什么也不做,因为10240不是1024的增量.但是当我尝试2048、4096等时,它也什么也没做.

on my Mac silently doesn't change the ulimit. I had originally thought it was not doing anything because 10240 is not an increment of 1024. But it also didn't do anything when I tried 2048, 4096, etc.

那么,什么是解决方案"?

So, what is "the" solution?

  • ulimit -n(无数字)会告诉您当前值是什么
  • 对我来说,在终端窗口中键入sudo ulimit -n 2048并不会更改ulimit(无论我尝试了多少个数字)
  • 在〜.bash_profile中添加'ulimit -n 4096'并打开一个新的终端即可解决问题
  • ulimit -n (without a number) will tell you what the current value is
  • for me, typing sudo ulimit -n 2048 in a terminal window did NOT change the ulimit (no matter what number I tried)
  • adding 'ulimit -n 4096' to ~.bash_profile and opening a new terminal solved the problem

这篇关于React Native + Jest EMFILE:打开文件过多错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆