簡體   English   中英

反應原生變換 - 錯誤找不到預設“babel-preset-react-native-stage-0

[英]react native transform - error couldn't find preset "babel-preset-react-native-stage-0

我開始彈出世博會,經過這么多的努力,我能夠解決所有構建問題。 當我使用'sudo react-native run-android'運行應用程序時,我開始收到以下錯誤

錯誤:

The development server returned response code 500
Bundling `index.android.js`  [development, non-minified, hmr disabled]  
0.0% (0/1), failed.
error: bundling failed: "TransformError: 

/Development/SourceCode/MobileApp/index.android.js: 
Couldn't find preset \"babel-preset-react-native-stage-0/decorator-support\" relative to directory \"/Development/SourceCode/MobileApp\""

我嘗試了在github和SO中給出的幾乎所有可能的修復

  1. 卸載最新版本的babel-preset-react-native並重新安裝sudo yarn add babel-preset-react-native@2.1.0
  2. 清除緩存Yarn Cache,npm緩存
  3. 刪除構建文件夾,刪除npm模塊並重新安裝所有模塊
  4. 很少有人通過移除守望者來解決問題,但我根本不使用守望者。
  5. 添加.babelrc提到裝飾器支持預設如下,此修復也無法正常工作。

.babelrc文件看起來像這樣

    {
      "presets": [
        "react-native",
        "babel-preset-react-native-stage-0/decorator-support"
      ],
      "env": {
        "development": {
          "plugins": [
            "transform-react-jsx-source"
          ]
        }
      }
    }

這些修復都不適合我。 使用babel-preset-react-native@2.1.0也沒有解決問題,因為這是主要修復。

嘗試使用正常的babel預設0: https//babeljs.io/docs/plugins/preset-stage-0

所以

"presets": ["react-native", "stage-0"]

如果您可以使用舊版本的React Native,可以使用以下內容在項目的根目錄中創建.babelrc文件:

{
  "presets": ["react-native"]
}

如果您在項目中使用了Expo,

嘗試:

  1. $ cd your_project
  2. $ nano .babelrc (或者你想要的任何編輯器)
  3. 復制並粘貼#A

如果您的項目中沒有.babelrc,那么:

  1. $ cd your_project
  2. touch .babelrc
  3. 復制並粘貼#A

#一種

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM