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

我跑了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

我怎样才能回到主分行?

推荐答案

你可以通过重新添加react-scripts个包来撤销Create React应用程序的"弹出"操作.根据你最喜欢的Package manager指挥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

并使用

$ 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

你成功了.....

Reactjs相关问答推荐

呈现组件元素(MAP)中的问题

Redux向后端发送请求时出现钩子问题

有没有办法将在服务器端全局获取的一些数据传递到Next&>13应用程序目录中的客户端组件?

如何访问子集合中的文档?

在继承值更改时重置react 挂钩窗体字段值

滚动视图样式高度没有任何区别

将 useRef 与 useImperativeHandle 一起使用时,React 不会重新渲染

React Native - 如何处理错误带有有效负载的NAVIGATE操作..未被任何导航器处理?

Next.js 和理智 | npm run build 时预渲染页面/时发生错误

如何在 JS 中绘制具有不同笔画宽度的样条线

在按钮单击中将动态参数传递给 React Query

我应该如何将字符串作为props 传递给 React 组件?

带有 webpack 错误多个文件匹配路由名称的 Expo-router.无法Bundle 或部署应用程序

使用带有搜索字符串的全局过滤器时如何在 React-Table 中进行精确匹配?

如何在 React 中使用 debounce hooks

React Native Realm 应用程序在发布构建后崩溃

如何保留我的下一个授权用户会话?所以我可以使用提供的 ID 在其他路由中获取数据

需要在窗口调整大小时更新 React 组件

React - 仅在变量为真时显示项目

bootstrap 导航栏切换器在 reactjs 中不起作用