35

My project was working fine but after installing react-redux and redux i can't start the project it shows me this error

Failed to compile.

webpack is not a function

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! project@0.1.0 start: `node scripts/start.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the project@0.1.0 start script.

npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

The screenshot of error in ternimal

Rajesh Pandya
  • 1,540
  • 4
  • 18
  • 31
Gulzar Yousaf
  • 371
  • 1
  • 3
  • 8
  • Do you have Webpack installed globally or locally? – James Mar 13 '19 at 10:49
  • 1
    it would be helpful to show your code for start.js if possible – BlackICE Mar 13 '19 at 10:55
  • i have created a start.js file here in this Plnkr, please take a look. http://plnkr.co/edit/EbQDizLIzOzJJ3rML0DU?p=preview – Gulzar Yousaf Mar 13 '19 at 14:14
  • @James i have installed it locally but i tried to install globally it showed me this error `npm WARN registry Unexpected warning for http://registry.npmjs.org/: Miscellaneous Warning ECONNABORTED: request to http://registry.npmjs.org/acorn failed, reason: connect ECONNABORTED 104.16.20.35:80 npm WARN registry Using stale package data from http://registry.npmjs.org/ due to a request error during revalidation. npm ERR! code ECONNABORTED npm ERR! errno ECONNABORTED npm ERR! request to http://registry.npmjs.org/@webassemblyjs%2fwasm-edit failed, reason: connect ECONNABORTED 104.16.20.35:80` – Gulzar Yousaf Mar 13 '19 at 14:18
  • @GulzarYousaf looks like you are trying to connect over an insecure connection (http), you'll need to check your npm settings. However, local is fine, can you post your package.json? – James Mar 13 '19 at 15:25

2 Answers2

130

I ran into a problem with this same symptom after upgrading all of my node modules including react and redux, but in particular react-dev-utils to v8.0.0. The createCompiler() function has been changed to expect an object rather than multiple parameters (I guess this will provide greater flexibility in the future).

I changed my start.js from:

const compiler = createCompiler(webpack, config, appName, urls, useYarn);

to:

const compiler = createCompiler({ webpack, config, appName, urls, useYarn });
s1mm0t
  • 6,035
  • 4
  • 38
  • 45
  • 2
    Worked like a charm - Thanks for sharing the solution! – hodgef Mar 17 '19 at 02:08
  • Had the exact same issue. I was wondering what caused it and even checked out a previous build wondering if I needed to revert any dependency updates for a last-known version. Your simple fix worked like a charm. OP, I'd make this the accepted answer. – sublimegeek Mar 18 '19 at 22:37
  • 1
    Did not work for me. `"react-dev-utils": "^9.0.1"`. Any suggestions? – Akhilesh Jul 23 '19 at 07:15
  • Afraid not. All I can really say is that I'm now on v9.0.1 and this solution is still working fine. Do you still get the webpack is not a function error? – s1mm0t Jul 24 '19 at 19:52
  • 1
    @Akhilesh it's because of one or both of the last boolean parameters, mine was like this: `const compiler = createCompiler({ webpack, config, appName, urls, false, false });` Either remove them, or make sure you pass them like `useYarn: false`... or use a variable with the same name like in this answer `useYarn` and `useTypeScript`. – tima Jul 25 '19 at 00:37
  • 1
    Unfortunately this did not work for me. I received ```TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received undefined``` after making the changes suggested in this answer. – Cameron Cobb Feb 24 '21 at 01:41
  • @CameronCobb This answer fixed that TypeError (for me): https://stackoverflow.com/a/62287792/107106 – Evan Jun 24 '21 at 15:43
-3

Simple npm install command worked form me

vicky
  • 5
  • 1
  • 4