17

When am trying to start gulp serve Its raise an error

module.js:338 throw err; ^

Error: Cannot find module 'browser-sync'

at Function.Module._resolveFilename (module.js:336:15)
at Function.Module._load (module.js:278:25)
at Module.require (module.js:365:17)
at require (module.js:384:17)
at Object.<anonymous> (/home/sajad/p_projects/my-project/gulpfile.js:17:19)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Module.require (module.js:365:17)
at require (module.js:384:17)

After that i tried sudo npm rm browser-sync && npm install browser-sync its raise follwing error

npm ERR! Linux 3.13.0-24-generic

npm ERR! argv "/usr/bin/node" "/usr/bin/npm" "install" "browser-sync" npm ERR! node v0.12.7 npm ERR! npm v2.11.3 npm ERR! file /home/sajad/.npm/escape-html/1.0.2/package/package.json npm ERR! code EJSONPARSE

npm ERR! Failed to parse json npm ERR! No data, empty input at 1:1 npm ERR! npm ERR! ^ npm ERR! File: /home/sajad/.npm/escape-html/1.0.2/package/package.json npm ERR! Failed to parse package.json data. npm ERR! package.json must be actual JSON, not just JavaScript. npm ERR! npm ERR! This is not a bug in npm. npm ERR! Tell the package author to fix their package.json file. JSON.parse

npm ERR! Please include the following file with any support request: npm ERR! /home/sajad/p_projects/my-project/npm-debug.log

Guide me how to start gulp serve and how resolve these error

Sajjad Murtaza
  • 1,444
  • 2
  • 16
  • 26

4 Answers4

33

I also had a same problem, I was able to solve it by entering this.

npm i browser-sync --save

Check this link here: https://github.com/brawlins/react-webpack-php-starter/issues/1

achooan
  • 491
  • 1
  • 5
  • 5
  • 1
    For me the problem was that I was installing using ```--save-dev```, removing it from devDependencies and install using just ```--save``` solved. Thanks! – Giovan Cruz Sep 13 '22 at 00:51
15

I tried these steps. Its work for me.

Globally install gulp.

Next need to install the project’s local dependencies (that’s where it’s looking for browser-sync). To do that,

cd into the project directory and run npm install.

Then try gulp serve.

You can also try following lines

npm i browser-sync --save 

then

npm start
Muhannad A.Alhariri
  • 3,702
  • 4
  • 30
  • 46
Sajjad Murtaza
  • 1,444
  • 2
  • 16
  • 26
10

You can try a :

npm cache clean 

as it looks like it's not related to your project but your npm files, and then re run npm install

ilse2005
  • 11,189
  • 5
  • 51
  • 75
sizrar
  • 101
  • 1
  • 6
  • This was the solution for me, only I had to add --force to the above cache clean statement, which solved the problem. – JakeMc Mar 26 '21 at 15:10
0

Are you behind a proxy? Because it happened once to me in a company, this specific node module wouldn't be installed because of the proxy. I had to install it without proxy to make it work. Just try on your phone or another network.

Vadorequest
  • 16,593
  • 24
  • 118
  • 215