webpack 在React中撤消“npm运行弹出”

qlvxas9a  于 2022-11-13  发布在  Webpack
关注(0)|答案(4)|浏览(166)

我尝试使用react CDN脚本测试我的 React应用 (使用create-react-app创建)的性能,我'npm run eject'添加了webpack externals依赖关系react和react-dom。
我在
webpack config**和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

如何恢复到主分支?

nwnhqdif

nwnhqdif1#

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

你成功了.....

7qhs6swi

7qhs6swi2#

如果你现在在master分支(其中配置是相同的npm run eject之前),然后尝试以下.

  • 删除node_module
  • npm install
  • npm start
n53p2ov0

n53p2ov03#

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

git checkout -- .

或:

git stash
ubof19bj

ubof19bj4#

DevTools不能完全关闭。但是您可以使其不可访问。

// Disbale Right click
document.oncontextmenu = function (e) {
  if (e.button == 2) {
      e.preventDefault();
      return false;
  }
}; 
  //disable f12 key
  document.onkeydown = function (event) {  
  event = (event || window.event);  
  if (event.keyCode == 123) {  
  return false;  
  }  
  }  
//disable ctrl key
document.addEventListener("keydown", function (event) {
  if (event.ctrlKey) {
      event.preventDefault();
  }   
});

相关问题