react-native init gives Error: Couldn't find p

2019-03-27 18:27发布

When I'm trying to start a new react-native project from scratch I'm getting this message.

/Users/jorgevenegas/Dev/Projects/testreact/List/node_modules/react-native/node_modules/babel-core/lib/transformation/file/options/option-manager.js:327
          throw new Error("Couldn't find preset " + JSON.stringify(val) + " relative to directory " + JSON.stringify(dirname));
          ^

Error: Couldn't find preset "es2015" relative to directory "/Users/jorgevenegas/Dev/Projects"

I have installed react-native-cli, of course. Using node v4.2.1, react-native 0.1.5, watchman and flow installed too.

Seems to be something related to babel. I can't figure out the reason, though.

I'm attaching a screenshot with a more detailed output.

Error Output

Thanks in the advance!

5条回答
Anthone
2楼-- · 2019-03-27 18:57

I went through something similar, maybe this can help. In my case it was because for some reason I had two instances of react-native installed on my system.

Check the output of

which -a react-native

If you get more than one path with react native installed, get rid of the one that gives you the same error when executing init directly with the full path (my case was one installed at /usr/local/bin/react-native, but yours could be slightly different).

After removing the wrong one, you should be able to init projects without any problems.

查看更多
姐就是有狂的资本
3楼-- · 2019-03-27 18:59

Add the following line to your .babelrc file:

{"presets": ["react"]}

I find solution from babel.io

查看更多
趁早两清
4楼-- · 2019-03-27 19:07

Try installing the following packages

npm install babel-preset-es2015 --save
npm install babel-preset-react --save
查看更多
爷的心禁止访问
5楼-- · 2019-03-27 19:17

This bugged me for a good 1 day. The issue was I had a .babelrc file up in my file hierarchy which was interfering with babel parsing. Got rid of that and it was fine. react-native uses es2015 by default so .babelrc is not required.

查看更多
看我几分像从前
6楼-- · 2019-03-27 19:18

I had the same problem. The solution for me was to switch from 'workspace/MyProject' (for you its "/Users/jorgevenegas/Dev/Projects" i guess) to 'workspace'.

I don't know why I had to do this, but when i ran

npm install babel-preset-es2015
npm install babel-preset-react

in my workspace instead, i could cd into 'MyProject' again and execute a react-native run-android from there.

Hope that helps at least some people encountering the same problem.

查看更多
登录 后发表回答