'Getting "Html Webpack Plugin: Error: Child compilation failed: Module.createRequire is not a function" when trying to run React app

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?



Solution 1:[1]

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.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1