简体   繁体   English

在React Native应用程序中使用npm软件包时的Babel错误

[英]Babel errors when using npm package in React Native application

I am building a React Native application. 我正在构建一个React Native应用程序。

I have tried using the following as an npm package in my application: https://github.com/MagicTheGathering/mtg-sdk-javascript/ 我尝试在我的应用程序中将以下内容用作npm软件包: https : //github.com/MagicTheGathering/mtg-sdk-javascript/

I try to import the package into one of my files using: import { card } from 'mtgsdk'; 我尝试使用以下方式将包导入到我的一个文件中: import { card } from 'mtgsdk'; and many other variations of import statements but none have worked. 以及导入语句的许多其他变体,但没有一个起作用。

I get the error: 我得到错误:

TransformError: /myproject/node_modules/mtgsdk/lib/index.js: Couldn't find preset "es2015" relative to directory /myproject/node_modules_mtgsdk TransformError:/myproject/node_modules/mtgsdk/lib/index.js:找不到相对于目录/ myproject / node_modules_mtgsdk的预设“ es2015”

What is the right way to import this package into my project? 将这个包导入我的项目的正确方法是什么? What knowledge is it that I lack about imports in javascript? 关于javascript导入,我缺乏什么知识?

Your babel doesn't know what exactly plugins you're going to use. 您的babel不知道您将要使用什么插件。

So you should add .babelrc file to the root of your project with next configuration: 因此,应使用以下配置将.babelrc文件添加到项目的根目录:

{
  presets: ["es2015"]
}

Oh, and dont forget about 哦,别忘了

npm install babel-preset-es2015 --save-dev

I hope it'll help 希望对您有帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM