Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot find module 'has-flag'

Getting below error while "npm run build" on server.On local machine working fine. Getting 500 response on server
node version:8.0
npm version: 5.0.3

    Error: Cannot find module 'has-flag'  
    at Function.Module._resolveFilename (module.js:485:15)  
    at Function.Module._load (module.js:437:25)  
    at Module.require (module.js:513:17)  
    at require (internal/module.js:11:18)  
    at Object.<anonymous>  
 (/usr/share/../../../node_modules/postcss/node_modules/supports-color/index.js:2:15)  
    at Module._compile (module.js:569:30)  
    at Object.Module._extensions..js (module.js:580:10)  
    at Module.load (module.js:503:32)  
    at tryModuleLoad (module.js:466:12)  
    at Function.Module._load (module.js:458:3)  
npm ERR! code ELIFECYCLE  
npm ERR! errno 1  
npm ERR! ***@0.1.0 build: `react-scripts build`  
npm ERR! Exit status 1  
npm ERR!   
npm ERR! Failed at the ***@0.1.0 build script.  
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
like image 664
Nishant Khandelwal Avatar asked Jul 18 '17 08:07

Nishant Khandelwal


People also ask

Can not find module node JS?

If you are getting the "Cannot find module" error when trying to run a local file, make sure that the path you passed to the node command points to a file that exists. For example, if you run node src/index. js , make sure that the path src/index. js points to an existing file.

Can not find module next?

A module not found error can occur for many different reasons: The module you're trying to import is not installed in your dependencies. The module you're trying to import is in a different directory. The module you're trying to import has a different casing.

What is Flag in npm?

npm install -s. The -s flag is a shorthand for the silent configuration, which sets the log level of your npm installation process to nothing. The following Terminal commands are all equal: npm install -s npm install --silent npm install --loglevel silent.

Can not find module npm?

To fix Cannot find module errors, install the modules properly by running a npm install command in the appropriate directory as your project's app. js or index. js file. or delete the node_modules folder and package-lock.


2 Answers

Try npm install --save has-flag. It looks like supports-color is requiring has-flag to be installed but it isn't. If you need to install any other packages you can just type npm install.

like image 123
brennanenanen Avatar answered Oct 01 '22 05:10

brennanenanen


The above didn't work for me, but deleting my node_modules and dist folders and rerunning npm install did.

like image 20
patrickbadley Avatar answered Oct 01 '22 04:10

patrickbadley