gilbsgilbs / babel-plugin-i18next-extract

Babel plugin that statically extracts i18next and react-i18next translation keys.
https://i18next-extract.netlify.com
MIT License
161 stars 37 forks source link

api.assertVersion is not a function #154

Closed maximys963 closed 4 years ago

maximys963 commented 4 years ago

Describe the bug

React Native project v 61.5 when trying to extract .t()

TypeError: api.assertVersion is not a function this error appears every time when I run yarn run babel -f .babelrc 'src/**/*.{js,jsx,ts,tsx}'

.babelrc

{ "presets": [ "stage-2", "react" ], "plugins": [ "i18next-extract" ] }

What actually happens

yarn run v1.21.1 $ /Users/maxim/Desktop/QT/mobile/node_modules/.bin/babel -f .babelrc 'src/**/*.{js,jsx,ts,tsx}' TypeError: api.assertVersion is not a function at plugin (/Users/maxim/Desktop/QT/mobile/node_modules/babel-plugin-i18next-extract/index.js:1884:7) at Function.memoisePluginContainer (/Users/maxim/Desktop/QT/mobile/node_modules/babel-core/lib/transformation/file/options/option-manager.js:113:13) at Function.normalisePlugin (/Users/maxim/Desktop/QT/mobile/node_modules/babel-core/lib/transformation/file/options/option-manager.js:146:32) at /Users/maxim/Desktop/QT/mobile/node_modules/babel-core/lib/transformation/file/options/option-manager.js:184:30 at Array.map (<anonymous>) at Function.normalisePlugins (/Users/maxim/Desktop/QT/mobile/node_modules/babel-core/lib/transformation/file/options/option-manager.js:158:20) at OptionManager.mergeOptions (/Users/maxim/Desktop/QT/mobile/node_modules/babel-core/lib/transformation/file/options/option-manager.js:234:36) at OptionManager.init (/Users/maxim/Desktop/QT/mobile/node_modules/babel-core/lib/transformation/file/options/option-manager.js:368:12) at File.initOptions (/Users/maxim/Desktop/QT/mobile/node_modules/babel-core/lib/transformation/file/index.js:212:65) at new File (/Users/maxim/Desktop/QT/mobile/node_modules/babel-core/lib/transformation/file/index.js:135:24) error Command failed with exit code 1.

Environment

clairefro commented 4 years ago

I'm experiencing the same

maximys963 commented 4 years ago

@clairefro I fix it by updating some babel packages, as i understand this error apears if some packege use old version of babel in my case old version of cli use 6 version instead 7

  "devDependencies": {
    "@babel/cli": "^7.8.4",
    "@babel/core": "7.6.2",
    "@babel/preset-react": "^7.9.4",
    "@babel/preset-stage-0": "^7.8.3",
    "@babel/runtime": "7.6.2",
    "@react-native-community/eslint-config": "0.0.5",
    "babel-jest": "24.9.0",
    "babel-plugin-i18next-extract": "^0.7.2",
    "babel-preset-react-app": "^9.1.2",

and have some changes in .babelrc

  "presets": ["react-app"],
  "plugins" : [
     [ "i18next-extract",
       {
         "outputPath" : "resources/{{locale}}/{{ns}}.json",
         "keyAsDefaultValue": "",
         "nsSeparator": "~",
         "keySeparator": "§ks",
         "locales": ['es']
       }
     ]
  ]
}