当前位置: 首页 > 工具软件 > Element React > 使用案例 >

React脚手架+element-react并暴露配置

孙元明
2023-12-01

1.安装create-react-app,npm install -g create-react-app

2.新建一个项目,create-react-app manager

3.进入项目,安装组件,cd manager——npm i element-react --save——npm install element-theme-default --save

4.此时启动项目npm start会报错:

D:\sdf\manager_react_\manager>npm start

> manager@0.1.0 start D:\sdf\manager_react_\manager
> react-scripts start

'react-scripts' 不是内部或外部命令,也不是可运行的程序
或批处理文件。
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! manager@0.1.0 start: `react-scripts start`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the manager@0.1.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\SEELE\AppData\Roaming\npm-cache\_logs\2019-06-19T02_46_23_451Z-debug.log

5.终止运行后执行npm install后安装缺少的依赖,npm install typescript@*,然后重新启动npm start,继续报错:

D:\sdf\manager_react_\manager>npm start

> manager@0.1.0 start D:\sdf\manager_react_\manager
> react-scripts start

Starting the development server...

BrowserslistError: Unknown browser query `android all`
BrowserslistError: Unknown browser query `android all`
BrowserslistError: Unknown browser query `android all`
BrowserslistError: Unknown browser query `android all`
BrowserslistError: Unknown browser query `android all`
BrowserslistError: Unknown browser query `android all`
BrowserslistError: Unknown browser query `android all`
BrowserslistError: Unknown browser query `android all`
BrowserslistError: Unknown browser query `android all`
BrowserslistError: Unknown browser query `android all`
BrowserslistError: Unknown browser query `android all`
BrowserslistError: Unknown browser query `android all`
Failed to compile.

./node_modules/element-react/dist/npm/es5/libs/animate/index.js
Module not found: Can't resolve 'react-hot-loader' in 'D:\sdf\manager_react_\manager\node_modules\element-react\dist\npm\es5\libs\animate'

6.终止运行后执行npm install react-hot-loader@next --save,更新react-hot-loader,然后重新启动npm start,成功运行:

D:\sdf\manager_react_\manager>npm start

> manager@0.1.0 start D:\sdf\manager_react_\manager
> react-scripts start

Starting the development server...

BrowserslistError: Unknown browser query `android all`
BrowserslistError: Unknown browser query `android all`
BrowserslistError: Unknown browser query `android all`
BrowserslistError: Unknown browser query `android all`
BrowserslistError: Unknown browser query `android all`
BrowserslistError: Unknown browser query `android all`
BrowserslistError: Unknown browser query `android all`
BrowserslistError: Unknown browser query `android all`
BrowserslistError: Unknown browser query `android all`
BrowserslistError: Unknown browser query `android all`
BrowserslistError: Unknown browser query `android all`
BrowserslistError: Unknown browser query `android all`
Compiled successfully!

You can now view manager in the browser.

  Local:            http://localhost:3000/
  On Your Network:  http://192.168.1.104:3000/

Note that the development build is not optimized.
To create a production build, use yarn build.


7.终止运行后执行npm run eject暴露配置信息,报错:

This git repository has untracked files or uncommitted changes:

.gitignore
M .idea/workspace.xml
D README.md
D manager/.idea/inspectionProfiles/Project_Default.xml
D manager/.idea/manager.iml
D manager/.idea/misc.xml
D manager/.idea/modules.xml
manager/.idea/workspace.xml
M manager/src/App.js
D package.json
D public/favicon.ico
D public/index.html
D public/manifest.json
D src/App.css
D src/App.js
D src/App.test.js
D src/index.css
D src/index.js
D src/logo.svg
D src/serviceWorker.js
D yarn.lock

Remove untracked files, stash or commit any changes, and try again.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! manager@0.1.0 eject: `react-scripts eject`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the manager@0.1.0 eject script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\SEELE\AppData\Roaming\npm-cache\_logs\2019-06-19T02_57_13_690Z-debug.log


8.依次执行git init——git add .——git commit -m "init"——npm run eject,执行成功;

9.在App.js中引入element-react后测试,执行npm start,成功运行。

 类似资料: