undo'npm run弹出' [英] undo 'npm run eject' in react

查看:75
本文介绍了undo'npm run弹出'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用react CDN脚本测试我的 React应用(由create-react-app创建)的性能,并且我做了'npm run弹出'来添加 webpack外部对象依赖关系和react-dom。



我在 webpack配置< script> 中轻松完成了此操作 index.html

  ... 
外部:{
react:'React',
'react-dom':'ReactDOM'
},
...

现在我想将其恢复为以前的状态



我正在使用 git ,我在另一个分支中进行了此实验。



我运行了 git checkout master npm start



结果很烦人

 > myapp@0.18.1开始/ home / code / serverSync / myapp / ui 
> react-scripts开始

sh:1:react-scripts:找不到

npm错误! Linux 4.15.0-23通用
npm ERR! argv / usr / bin / node / usr / bin / npm开始
npm错误!节点v8.10.0
npm错误! npm v3.5.2
npm错误!文件sh
npm错误!代码ELIFECYCLE
npm错误! errno ENOENT
npm错误! syscall产生
npm错误! myapp@0.18.1 start:`react-scripts start`
npm错误!产生ENOENT
npm错误!
npm错误!在myapp@0.18.1启动脚本 react-scripts start上失败。
npm错误!确保已安装最新版本的node.js和npm。
npm错误!如果这样做,这很可能是myapp软件包
npm ERR的问题!不与npm本身。
npm错误!告诉作者这在您的系统上失败:
npm ERR! react-scripts开始
npm ERR!您可以通过以下方式获取有关如何为此项目打开问题的信息:
npm ERR! npm bug myapp
npm错误!或者,如果不可用,则可以通过以下方式获取其信息:
npm ERR! npm所有者ls myapp
npm错误!上面可能还有其他日志记录输出。

npm错误!请在任何支持请求中包括以下文件:
npm错误! /home/code/serverSync/myapp/ui/npm-debug.log

我该如何还原掌握分支吗?

解决方案

您可以通过添加 react来撤消Create React App应用程序的弹出操作-脚本打包回来。根据您最喜欢的包装经理

来命令yarn或npm。 p $ p> $纱线运行弹出/ npm运行弹出
?您确定要弹出吗?此动作是永久性的。 (是/否)是

现在的解决方案是:-

  $ rm -r scripts / //删除您的脚本文件夹
$ rm -r config / //删除您的配置文件夹
$ rm -r node_modules // //删除您的node_modules文件夹

并添加反应脚本打包返回

  $ yarn添加react-scripts / npm install react-scripts 

package.json 文件中,您需要更改脚本 还原到以前的状态:

 脚本:{
+ start:反应脚本开始,
+ build:反应脚本构建,
+ test:反应脚本测试--env = jsdom,
+ eject:反应-脚本弹出
-开始:节点脚本/start.js,
-构建:节点脚本/build.js,
-测试: node scripts / test.js --env = jsdom
}

现在全部安装依赖使用:-

  $ yarn install / npm install 

然后您就可以好了

  $纱线开始/ npm开始

您做到了.....


I was trying to test the performance of my React app(created with create-react-app) with react CDN script and i did 'npm run eject' to add webpack externals dependencies react and react-dom.

I did that with ease in webpack config and <script> in index.html

...
externals: {
    react: 'React',
    'react-dom':'ReactDOM'
},
...

Now I want to revert it back to previous state

I am using git and i did this experiment in a seperate branch.

I ran git checkout master and npm start

The result was annoying

> myapp@0.18.1 start /home/code/serverSync/myapp/ui
> react-scripts start

sh: 1: react-scripts: not found

npm ERR! Linux 4.15.0-23-generic
npm ERR! argv "/usr/bin/node" "/usr/bin/npm" "start"
npm ERR! node v8.10.0
npm ERR! npm  v3.5.2
npm ERR! file sh
npm ERR! code ELIFECYCLE
npm ERR! errno ENOENT
npm ERR! syscall spawn
npm ERR! myapp@0.18.1 start: `react-scripts start`
npm ERR! spawn ENOENT
npm ERR! 
npm ERR! Failed at the myapp@0.18.1 start script 'react-scripts start'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the myapp package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     react-scripts start
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs myapp
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls myapp
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /home/code/serverSync/myapp/ui/npm-debug.log

how can i revert back to master branch ?

解决方案

You can undo the "eject" operation of a Create React App app by adding the react-scripts package back. Command yarn or npm based on Your favorite Package manager

What you did:

$ yarn run eject/ npm run eject 
? Are you sure you want to eject? This action is permanent. (Yes/No)Yes

Now Solution for it is to:-

$ rm -r scripts/  //Remove Your scripts folder 
$ rm -r config/   //Remove Your config folder
$ rm -r node_modules//  //Remove Your node_modules folder

And Add react-scripts package back using

$ yarn add react-scripts / npm install react-scripts 

And inside the package.json file you'll need to change the "scripts" to their former state:

"scripts": {
+    "start": "react-scripts start",                 
+    "build": "react-scripts build",                 
+    "test": "react-scripts test --env=jsdom",       
+    "eject": "react-scripts eject"                  
-    "start": "node scripts/start.js",               
-    "build": "node scripts/build.js",                
-    "test": "node scripts/test.js --env=jsdom"      
  }

Now install all dependency using:-

  $ yarn install / npm install 

And You are good to go

$ yarn start / npm start

You made it.....

这篇关于undo'npm run弹出'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆