在react

时间:2018-07-21 09:33:23

标签: reactjs webpack create-react-app

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

我在 webpack配置<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

我如何恢复到主分支?

3 个答案:

答案 0 :(得分:4)

您可以通过添加 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

然后使用

重新添加反应脚本程序包

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

package.json 文件中,您需要将“脚本” 更改为以前的状态:

"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

您做到了.....

答案 1 :(得分:3)

如果您现在位于import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner input=new Scanner(System.in); double x=input.nextDouble(); x = (xe3) + (xe2) + x + 1; System.out.println(x); } } 分支(其配置与之前的master相同),请尝试执行以下操作。

  • 删除npm run eject
  • node_module
  • npm install

答案 2 :(得分:0)

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

git checkout -- .

或:

git stash