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

Viewed 1953

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?

2 Answers

Update the node version on Linux through the steps below, which fixed the issue I also encountered.

Step1:

sudo apt-get install curl

Step2 (the 18.x is the latest version) :

curl -sL https://deb.nodesource.com/setup_18.x | sudo -E bash -

Step3:

sudo apt-get install nodejs

Step4 (check version):

node -v

Then run npm start that would be fixed.

Related