2

I get the following error when running npm start.

> app@0.1.0 start /Users/user/Desktop/react-tutorial
> react-scripts start

require(...) is not a function
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! app@0.1.0 start: `react-scripts start`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the app@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:

Here is the actual error

0 info it worked if it ends with ok
1 verbose cli [ '/usr/local/bin/node', '/usr/local/bin/npm', 'start' ]
2 info using npm@6.4.1
3 info using node@v10.15.0
4 verbose run-script [ 'prestart', 'start', 'poststart' ]
5 info lifecycle app@0.1.0~prestart: app@0.1.0
6 info lifecycle app@0.1.0~start: app@0.1.0
7 verbose lifecycle app@0.1.0~start: unsafe-perm in lifecycle true
8 verbose lifecycle app@0.1.0~start: PATH: /usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/Users/user/Desktop/react-tutorial/node_modules/.bin:/Library/Java/JavaVirtualMachines/jdk-9.0.4.jdk/Contents/Home/bin:/Users/user/Library/Android/sdk/tools:/Users/user/Library/Android/sdk/platform-tools:/Library/Frameworks/Python.framework/Versions/3.6/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/share/dotnet:~/.dotnet/tools:/Library/Frameworks/Mono.framework/Versions/Current/Commands:/Applications/Xamarin Workbooks.app/Contents/SharedSupport/path-bin:/opt/local/share/java/android-sdk-macosx/platform-tools:/Users/user/.android-sdk-macosx/platform-tools/:/Users/user/.android-sdk-macosx/platform-tools/:/Users/user/Library/Android/sdk/platform-tools/
9 verbose lifecycle app@0.1.0~start: CWD: /Users/user/Desktop/react-tutorial
10 silly lifecycle app@0.1.0~start: Args: [ '-c', 'react-scripts start' ]
11 silly lifecycle app@0.1.0~start: Returned: code: 1  signal: null
12 info lifecycle app@0.1.0~start: Failed to exec start script
13 verbose stack Error: app@0.1.0 start: `react-scripts start`
13 verbose stack Exit status 1
13 verbose stack     at EventEmitter.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:301:16)
13 verbose stack     at EventEmitter.emit (events.js:182:13)
13 verbose stack     at ChildProcess.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
13 verbose stack     at ChildProcess.emit (events.js:182:13)
13 verbose stack     at maybeClose (internal/child_process.js:962:16)
13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:251:5)
14 verbose pkgid app@0.1.0
15 verbose cwd /Users/user/Desktop/react-tutorial
16 verbose Darwin 16.7.0
17 verbose argv "/usr/local/bin/node" "/usr/local/bin/npm" "start"
18 verbose node v10.15.0
19 verbose npm  v6.4.1
20 error code ELIFECYCLE
21 error errno 1
22 error app@0.1.0 start: `react-scripts start`
22 error Exit status 1
23 error Failed at the app@0.1.0 start script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]

This just started to happen when i restarted computer...why

I can't find anywhere where I am calling require()... maybe a plugin I installed?

letsCode
  • 2,774
  • 1
  • 13
  • 37

4 Answers4

4

In my case, had created a setupProxy.js file at project level, later i removed the configurations in it but not the file. Hence the mentioned error in question was thrown. To resolve, try one of the following according to your need,

  1. update the proper configuration in the setupProxy.js
  2. delete the setupProxy.js if not needed
  3. don't leave the setupProxy.js as empty file
Sasi Kumar M
  • 2,440
  • 1
  • 23
  • 23
1
  1. Delete nodes_modules
  2. npm install -g npm
  3. npm install & npm install -D
  4. npm run start
CraftyMonkey
  • 395
  • 1
  • 6
1

Thanks to @Srinivas's response in the comment of the question.

Delete the generated setupProxy.js file. If you want to use a proxy, instead add it into your package.json file.

  "proxy": "http://localhost:3000",

For a setupProxy.js file like so:

const proxy = require('http-proxy-middleware');

// tells the browser to direct any relative reference paths to the below 
// domain instead of our own
module.exports = function(app) {
  app.use(proxy('/api/*', { target: 'http://localhost:3000' }));*/
};
jboxxx
  • 707
  • 10
  • 19
1

When you are setting up a Proxy to make a request to a different server

First Step is to install the dependency

npm install --save http-proxy-middleware

Next create setupProxy.js file

setupProxy.js

const { createProxyMiddleware } = require('http-proxy-middleware');

module.exports = function(app) {
  app.use(
    '/api',
    createProxyMiddleware({
       target: 'http://localhost:3001',
       changeOrigin: true
    })
  );
};
Sandeep Mukherjee
  • 673
  • 1
  • 9
  • 17