【问题标题】:undo 'npm run eject' in react在反应中撤消'npm run弹出'
【发布时间】:2018-12-29 11:38:46
【问题描述】:

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

我在 webpack config<script>index.html

中轻松做到了这一点
...
externals: {
    react: 'React',
    'react-dom':'ReactDOM'
},
...

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

我正在使用 git,我在一个单独的分支中做了这个实验。

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

如何恢复到 master 分支?

【问题讨论】:

  • 你可能需要再次 npm install ,看起来弹出卸载了一些依赖项。
  • 我也关注了该链接,但没有运气(rm -r scripts/ , $ rm -r config/ 在我运行 git checkout 时已经为空)
  • 遵循@jonrsharpe 建议npm install 并已解决(react-scripts@1.1.0 已重新安装)。谢谢。

标签: reactjs webpack create-react-app


【解决方案1】:

您可以通过添加 react-scripts 包来撤消 Create React App 应用程序的“弹出”操作。基于你最喜欢的包管理器

的命令 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

你做到了.....

【讨论】:

    【解决方案2】:

    如果您现在在master 分支(与之前npm run eject 的配置相同),请尝试关注。

    • 删除node_module
    • npm install
    • npm start

    【讨论】:

      【解决方案3】:

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

      git checkout -- .
      

      或:

      git stash
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-03-11
        • 2019-04-27
        • 1970-01-01
        • 2021-03-26
        • 2020-10-26
        • 2019-08-17
        • 1970-01-01
        • 2021-11-25
        相关资源
        最近更新 更多