[英]create-react-app returns an Error: Cannot find module 'react-scripts/scripts/init.js' when executed
[英]UnhandledPromiseRejectionWarning: Error: Cannot find module '/MyProject/node_modules/react-native-scripts/build/scripts/init.js'
我正在嘗試使用 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
答案如下。
Create React Native App 已更改,現在使用新的 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,允許您運行模擬器、發送鏈接或發布您的項目。
這些 javascript 庫正在迅速變化。 如果您使用的是紗線,這在 2020 年適用於 macOS
brew install yarn
sudo yarn global add expo-cli
expo init <project name>
然后將在以下名稱下創建一個項目
cd <project name>
yarn start
發生錯誤,因為 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
您可能正在查看舊教程,最近使用 react-native https://github.com/react-community/create-react-native-app/issues/770進行了更改
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.