ERROR in Error: Child compilation failed: Cannot find module 'handlebars'

Matt Goo picture Matt Goo · Aug 30, 2016 · Viewed 7.6k times · Source

I've recently erased all node_modules and did a fresh npm install. And keep getting this error:

ERROR in   Error: Child compilation failed:
  Cannot find module 'handlebars'

  - compiler.js:76 
    [wallet-admin]/[html-webpack-plugin]/lib/compiler.js:76:16

  - Compiler.js:214 Compiler.<anonymous>
    [wallet-admin]/[webpack]/lib/Compiler.js:214:10

  - Compiler.js:403 
    [wallet-admin]/[webpack]/lib/Compiler.js:403:12

  - Tapable.js:67 Compiler.next
    [wallet-admin]/[tapable]/lib/Tapable.js:67:11

  - CachePlugin.js:40 Compiler.<anonymous>
    [wallet-admin]/[webpack]/lib/CachePlugin.js:40:4

  - Tapable.js:71 Compiler.applyPluginsAsync
    [wallet-admin]/[tapable]/lib/Tapable.js:71:13

  - Compiler.js:400 Compiler.<anonymous>
    [wallet-admin]/[webpack]/lib/Compiler.js:400:9

Child html-webpack-plugin for "index.html":

    ERROR in Cannot find module 'handlebars'

Not sure what is going on...I've tried changing all versions of: html-webpack-plugin, webpack, handlebars-loader thinking it is a versioning issue. It doesn't seem to be. Any ideas?

Answer

Matt Goo picture Matt Goo · Aug 30, 2016

Thankfully I figured out my own issue...in my webpack.config.js file under modules, I had the handlebars loader as:

module: {
  loaders: [
    {
      // this should be /\.handlebars$/
      test: /\.hbs$/,
      exclude: /(node_modules)/,
      loader: 'handlebars-loader'
    }
  ]
}

But for some reason it needed the extension to be .handlebars instead of just .hbs even though my file is a .hbs. One mystery solved, another found. But it works!