gpt4 book ai didi

reactjs - react-app-rewire 的 npm start run 问题

转载 作者:行者123 更新时间:2023-12-03 21:00:51 27 4
gpt4 key购买 nike

我正在尝试在 reactjs 项目中使用 mobx。我已经使用 yarn add 命令安装了这些包:

yarn add mobx mobx-react react-app-rewired react-app-rewire-mobx

之后,我在 package.json 文件中用 react-app-rewired 替换了 react-scripts。
"dependencies": {
"mobx": "^5.13.0",
"mobx-react": "^6.1.3",
"react": "^16.9.0",
"react-app-rewire-mobx": "^1.0.9",
"react-app-rewired": "^2.1.3",
"react-dom": "^16.9.0",
"react-scripts": "3.1.1"
},
"scripts": {
"start": "react-app-rewired start",
"build": "react-app-rewired build",
"test": "react-app-rewired test",
"eject": "react-app-rewired eject"
},

但是当我在终端中输入“npm start”命令时,它给了我错误并且什么也没有启动。这里的错误行:
 D:\Projects\react\todo>npm start

> todo@0.1.0 start D:\Projects\react\todo
> react-app-rewired start

D:\Projects\react\todo\node_modules\react-scripts\node_modules\resolve\lib\sync.js:76
throw err;
^

Error: Cannot find module 'typescript' from 'D:\Projects\react \todo\node_modules'
at Function.module.exports [as sync] (D:\Projects\react \todo\node_modules\react-scripts\node_modules\resolve\lib\sync.js:74:15)
at getModules (D:\Projects\react\todo\node_modules\react-scripts \config\modules.js:75:32)
at Object.<anonymous> (D:\Projects\react\todo\node_modules\react- scripts\config\modules.js:96:18)
at Module._compile (internal/modules/cjs/loader.js:701:30)
at Object.Module._extensions..js (internal/modules /cjs/loader.js:712:10)
at Module.load (internal/modules/cjs/loader.js:600:32)
at tryModuleLoad (internal/modules/cjs/loader.js:539:12)
at Function.Module._load (internal/modules/cjs/loader.js:531:3)
at Module.require (internal/modules/cjs/loader.js:637:17)
at require (internal/modules/cjs/helpers.js:22:18)
at Object.<anonymous> (D:\Projects\react\todo\node_modules\react- scripts\config\webpack.config.js:31:17)
at Module._compile (internal/modules/cjs/loader.js:701:30)
at Object.Module._extensions..js (internal/modules /cjs/loader.js:712:10)
at Module.load (internal/modules/cjs/loader.js:600:32)
at tryModuleLoad (internal/modules/cjs/loader.js:539:12)
at Function.Module._load (internal/modules/cjs/loader.js:531:3)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! todo@0.1.0 start: `react-app-rewired start`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the todo@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\Me\AppData\Roaming\npm-cache\_logs \2019-08-29T17_54_55_905Z-debug.log

我是 reactjs 的新手,不熟悉这些错误及其解决方案。你能帮我吗?

最佳答案

配置 react-app-rewired
安装包
首先,让我们使用以下命令安装软件包。

yarn add react-app-rewired -D
配置脚本
react-app-rewired 的操作非常简单。为了让它在我们的项目中工作,只需访问我们的 package.json 并更改脚本(EJECT 除外),将 react-scripts 替换为 react-app-rewired,如下所示:
//package.json
"scripts": {
"start": "react-app-rewired start",
"build": "react-app-rewired build",
"test": "react-app-rewired test",
"eject": "react-scripts eject"
},

关于reactjs - react-app-rewire 的 npm start run 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57716040/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com