1

Trying to run npm start within my React app is causing the following:

  Error: Child compilation failed:
  Module.createRequire is not a function
  
  - child-compiler.js:169 childCompiler.runAsChild
    [fit_with_us]/[html-webpack-plugin]/lib/child-compiler.js:169:18
  
  - Compiler.js:551 finalCallback
    [fit_with_us]/[webpack]/lib/Compiler.js:551:5
  
  - Compiler.js:577 compile
    [fit_with_us]/[webpack]/lib/Compiler.js:577:11
  
  - Compiler.js:1196 hooks.afterCompile.callAsync.err
    [fit_with_us]/[webpack]/lib/Compiler.js:1196:17

I've tried deleting my node_modules and package-lock. I've tried deleting my cache. I've tried upgrading my node version to 14 and 16. No luck. Any ideas?

cachius
  • 1,423
  • 5
  • 20
lucss
  • 11
  • 1
  • What are your dependencies? Did you also try to update them or npm? – cachius May 09 '22 at 22:19
  • Does this answer your question? [ERROR in Module.createRequire is not a function](https://stackoverflow.com/questions/70390777/error-in-module-createrequire-is-not-a-function) – cachius May 10 '22 at 08:32
  • @cachius Turns out my nvm use command didn't stick. I was using node v10 even after I ran the command. I ran it properly, ran the app, and it worked – lucss May 14 '22 at 06:00

1 Answers1

0

Module.createRequire was added in node 12.2.0. This error means code written for node >=12.2.0 is run with node < 12.2.0.

This can be caused unintentionally by a non sticky nvm use command.

cachius
  • 1,423
  • 5
  • 20