UnhandledPromiseRejectionWarning:错误:找不到模块'/MyProject/node_modules/react-native-scripts/build/scripts/init.js'

时间:2018-09-24 04:53:23

标签: node.js reactjs react-native

我正在尝试使用Facebook React Native教程构建一个新的React Native项目。此命令以前对我有用,但是突然之间我现在收到此错误消息。

(node:14866) UnhandledPromiseRejectionWarning: Error: Cannot find module '/MyProject/node_modules/react-native-scripts/build/scripts/init.js'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:581:15)
at Function.Module._load (internal/modules/cjs/loader.js:507:25)
at Module.require (internal/modules/cjs/loader.js:637:17)
at require (internal/modules/cjs/helpers.js:20:18)
at _callee2$ (/.config/yarn/global/node_modules/create-react-native-app/build/index.js:128:32)
at tryCatch (/.config/yarn/global/node_modules/regenerator-runtime/runtime.js:62:40)
at Generator.invoke [as _invoke] (/.config/yarn/global/node_modules/regenerator-runtime/runtime.js:296:22)
at Generator.prototype.(anonymous function) [as next] (/.config/yarn/global/node_modules/regenerator-runtime/runtime.js:114:21)
at step (/.config/yarn/global/node_modules/babel-runtime/helpers/asyncToGenerator.js:17:30)
at /.config/yarn/global/node_modules/babel-runtime/helpers/asyncToGenerator.js:28:13
(node:14866) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:14866) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

我不确定发生了什么变化,但是找不到解决方法。有人可以帮忙吗?

编辑:在此处找到启动React Native应用程序的新方法:https://github.com/react-community/create-react-native-app

答案在下面。

4 个答案:

答案 0 :(得分:3)

创建React Native应用已更改,现在使用了新的Expo CLI。

我按照此处的说明进行操作:https://github.com/react-community/create-react-native-app

$ npm install -g expo-cli
$ expo init AwesomeProject
$ cd AwesomeProject
$ expo start

现在它将打开一个新的localhost Metro Bundler,它具有一个GUI,可让您运行模拟器,发送链接或发布项目。

答案 1 :(得分:0)

这些javascript库正在快速变化。如果您使用的是纱线,那么这在2020年适用于macOS对我来说

brew install yarn
sudo yarn global add expo-cli
expo init <project name>

然后将以

的名称创建一个项目。
cd <project name>
yarn start

答案 2 :(得分:0)

发生错误,因为create-react-native-app使用的 react-native-scripts 版本错误。它使用react-native-scripts的最后一个稳定版本2.01。此版本不包含错误消息中提到的 init.js 文件。

要解决该错误,我们需要使用与create-react-native-app兼容的react-native-scripts版本。 react-native-scripts的1.4.0版本似乎兼容,因为它是在create-react-native-app之后几个月发布的。

因此,要使用create-react-native-app创建一个新项目,请使用以下命令:create-react-native-app --scripts-version 1.4.0 [project-name]。此解决方案适用于create-react-native-app版本 1.0.0

答案 3 :(得分:-1)

您可能正在看一个旧教程,react-native最近发生了变化 https://github.com/react-community/create-react-native-app/issues/770

相关问题