为啥我不能运行我的 React Native 项目?
Posted
技术标签:
【中文标题】为啥我不能运行我的 React Native 项目?【英文标题】:Why can't I run my React Native project?为什么我不能运行我的 React Native 项目? 【发布时间】:2017-06-28 14:37:27 【问题描述】:我看不出我是如何在我的项目中遇到这些错误的。
我正在尝试在我的模拟器中运行index.ios.js
(第一次创建项目时 React Native 附带的文件,欢迎屏幕)文件,但它不允许我这样做。我已经发布了以下错误之一的图片。
另一个error
是当我点击Run
时。
如果有帮助,我还将在下面包含 package.json
和 .eslint
文件:文件。
error
:
import React, Component from 'react';
^^^^^^
SyntaxError: Unexpected token import
at Object.exports.runInThisContext (vm.js:76:16)
at Module._compile (module.js:542:28)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.runMain (module.js:604:10)
at run (bootstrap_node.js:394:7)
at startup (bootstrap_node.js:149:9)
at bootstrap_node.js:509:3
Process finished with exit code 1
package.json
文件:
"name": "App",
"version": "0.0.1",
"private": true,
"scripts":
"start": "node node_modules/react-native/local-cli/cli.js start",
"test": "jest"
,
"dependencies":
"react": "^16.0.0-alpha.6",
"react-native": "^0.43.3",
"react-native-datepicker": "^1.4.7"
,
"devDependencies":
"babel-jest": "19.0.0",
"babel-preset-react-native": "1.9.1",
"eslint-config-rallycoding": "^3.2.0",
"jest": "19.0.2",
"react-test-renderer": "16.0.0-alpha.6"
,
"jest":
"preset": "react-native"
.eslint
文件:
"parserOptions":
"ecmaVersion": 6,
"sourceType": "module",
"ecmaFeatures":
"jsx": true
,
"rules":
"semi": 2
【问题讨论】:
你可能需要让 ESLint 知道你正在使用 ES2015 导入。 @evolutionxbox 我该怎么做?我没有看到这样的选择。 常读牌匾:eslint.org/docs/user-guide/configuring @evolutionxbox 呃,这是一个非常模糊的答案。 这不是一个答案,它是一条评论,要求您阅读 ESLint 文档,其中告诉您如何删除错误。特别是ecmaFeatures
【参考方案1】:
运行 index.ios.js
时出错:似乎您正在使用 Node.js 运行配置来启动您的应用程序,但 Node.js 本身不支持 ES6 模块(因此出现语法错误导入时),当然,它不支持 react-native cli 选项,所以像你一样运行 node index.ios.js
不会在 ios 模拟器中启动你的应用程序。您应该改用 React Native 运行配置。请参阅https://blog.jetbrains.com/webstorm/2016/12/developing-mobile-apps-with-react-native-in-webstorm/,运行和调试应用部分
ESLint:你的 ESLint 配置 (Preferences | Languages & Frameworks | javascript | Code Quality Tools | ESLint
) 是什么样的?你是选择全局还是本地 ESLint?
【讨论】:
以上是关于为啥我不能运行我的 React Native 项目?的主要内容,如果未能解决你的问题,请参考以下文章
为啥我不能在 Windows 上运行 react-native 应用程序
为啥我不能在 react native 中导入我的自定义组件
Nativebase React Native 为啥我不能在输入中传递一个数字
为啥我不能在 ios 设备上关闭并重新打开 react-native 调试?
为啥我不能在 react native 中以编程方式添加道具?
我尝试使用 react-native run-android 命令运行我的 react native 项目:我的模拟器设置得很好。请问有啥问题