14

I'm trying to run a react project . and after I run command : npm start , it gave me an error:

sh: SET: command not found
npm ERR! file sh
npm ERR! code ELIFECYCLE
npm ERR! errno ENOENT
npm ERR! syscall spawn
npm ERR! materials-trace@0.1.0 start: `SET PORT=3100 && node scripts/start.js`
npm ERR! spawn ENOENT
npm ERR! 
npm ERR! Failed at the materials-trace@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!     /Users/jzhu321/.npm/_logs/2019-04-22T09_29_51_770Z-debug.log

and I have found the config here in package.json :

  "scripts": {
    "start": "SET PORT=3100 && node scripts/start.js",
    "build": "node scripts/build.js",
    "test": "node scripts/test.js"
  },

How do I fix this problem?

Neko
  • 581
  • 1
  • 9
  • 24

2 Answers2

28

Shell script doesnot have SET command, just had: set

it should be :

"start": "set PORT=3100 && node scripts/start.js",
Thanh Nguyen Van
  • 10,292
  • 6
  • 35
  • 53
  • 2
    For a cross-platform solution consider utilizing [cross-env](https://github.com/kentcdodds/cross-env) to set environment variables. – RobC Apr 23 '19 at 10:10
  • Correct: the "start" target in `package.json` was using Windows syntax instead of Linux shell syntax. In this example, the "test" and "build" targets invoked NodeJS, which is platform agnostic - they were both OK. One alternative for "start" is `set PORT=3100...`. Another could be `export PORT=3100...`. As RobC noted, yet another alternative is to use [cross-env](https://github.com/kentcdodds/cross-env). – FoggyDay Nov 22 '19 at 23:28
6

Change SET to set your code should be

 "scripts": {
"start": "set PORT=3100 && node scripts/start.js",
"build": "node scripts/build.js",
"test": "node scripts/test.js"
},

Removing the set command will also result in error sh: 1: PORT: not found if there are spaces so you can use PORT=3100

Lameck Meshack
  • 4,707
  • 2
  • 10
  • 17