React Native无法解析babel插件

时间:2018-09-01 04:03:28

标签: javascript react-native npm babeljs babel

错误消息

在“ \ project \ directory \ path \ .babelrc.env.development”中指定的未知插件\“ require-all \”

我的文件

.babelrc

{
  "presets": ["babel-preset-expo"],
  "env": {
    "development": {
      "plugins": ["transform-react-jsx-source", "require-all"]

    }
   }
}

package.json

{
  "name": "text-adventure-app",
  "version": "0.1.0",
  "private": true,
  "devDependencies": {
    "babel-plugin-require-all": "0.0.1",
    "jest-expo": "~27.0.0",
    "react-native-scripts": "1.14.0",
    "react-test-renderer": "16.3.1"
  },
  "main": "./node_modules/react-native-scripts/build/bin/crna-entry.js",
  "scripts": {
    "start": "react-native-scripts start",
    "eject": "react-native-scripts eject",
    "android": "react-native-scripts android",
    "ios": "react-native-scripts ios",
    "test": "jest"
  },
  "jest": {
    "preset": "jest-expo"
  },
  "dependencies": {
    "clear": "^0.1.0",
    "create-react-class": "^15.6.3",
    "expo": "^27.0.1",
    "react": "16.3.1",
    "react-native": "~0.55.2",
    "react-native-typewriter": "^0.5.3"
  }
}

babel-plugin-require-all

通过npm安装,如下所示: https://github.com/dushaobindoudou/babel-plugin-require-all

我尝试过的事情

  • 将“全部需要”更改为“ babel-plugin-require-all”
  • 删除并重新安装我的node_modules
  • 清除npm缓存
  • 向互联网征询了有关包含babel插件的建议

1 个答案:

答案 0 :(得分:1)

该插件的package.json中存在问题-属性中有一个额外的main(空格),这意味着babel无法解决它。我通过从行尾删除空格来验证了这一点,并且它可以成功编译。

在这种情况下,我的建议是使用其他程序包(也许像https://github.com/vihanb/babel-plugin-wildcard这样可以解决问题)或向babel-plugin-require-all程序包提交拉取请求,以删除多余的空间。