'npm start run problem with react-app-rewire

I am trying to use mobx in a reactjs project. I have installed these packages using yarn add command:

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

after that I have replaced react-scripts with react-app-rewired in package.json file.

"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"
},

But when I type 'npm start' command in terminal it gives me error and nothing starts. Here the error lines:

 D:\Projects\react\todo>npm start

 > [email protected] 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! [email protected] start: `react-app-rewired start`
   npm ERR! Exit status 1
   npm ERR!
   npm ERR! Failed at the [email protected] 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

I am new to reactjs and not familiar with these errors and their solutions. Would you help me?



Solution 1:[1]

Configuring react-app-rewired Installing the package First, let's install the package with the command below.

yarn add react-app-rewired -D

Configuring the scripts The operation of react-app-rewired is quite simple. To make it work in our project, just access our package.json and change the scripts (except for EJECT), replacing react-scripts with react-app-rewired, as shown below:

//package.json
  "scripts": {
    "start": "react-app-rewired start",
    "build": "react-app-rewired build",
    "test": "react-app-rewired test",
    "eject": "react-scripts eject"
  },

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Dinesh M