在反应中撤消 'npm run eject'

undo 'npm run eject' in react

我试图用 React CDN 脚本测试我的 React 应用程序(使用 create-react-app 创建)的性能,我做了 'npm run eject' 添加 webpack externals 依赖 react 和 react-dom。

我在 webpack config<script> 中轻松做到了 index.html

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

现在我想把它恢复到以前的状态

我正在使用 git 并且我在单独的 b运行ch.

中做了这个实验

我运行git checkout masternpm start

结果很烦人

> 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

我怎样才能恢复到主 b运行ch?

如果您现在在 master 分支(配置与之前 npm run eject 相同),请尝试以下操作。

  • 删除node_module
  • npm install
  • npm start

您可以通过添加 react-scripts 包来撤消创建 React App 应用程序的 "eject" 操作。根据您最喜欢的命令 yarn 或 npm 包管理器

你做了什么:

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

现在解决方法是:-

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

并使用

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

package.json 文件中,您需要将 "scripts" 更改为之前的状态:

"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"      
  }

现在使用以下方式安装所有依赖项:-

  $ yarn install / npm install 

你很高兴去

$ yarn start / npm start

你做到了......

删除然后npm install提到的方法是正确的。但是,如果您使用 git(或任何版本控制),只需执行:

git checkout -- .

或:

git stash