webpack + require handlebars error

See original GitHub issue

I get the following error simply by using require handlebars.

▶ webpack --display-modules   
Hash: bdb0fe35e2f8bde783e5
Version: webpack 1.12.12
Time: 116ms
         Asset     Size  Chunks             Chunk Names
bundle.main.js  2.82 kB       0  [emitted]  main
   [0] ./src/index.js 150 bytes {0} [built]
   [1] ./~/handlebars/lib/index.js 792 bytes {0} [built] [3 warnings] [3 errors]

WARNING in ./~/handlebars/lib/index.js
require.extensions is not supported by webpack. Use a loader instead.

WARNING in ./~/handlebars/lib/index.js
require.extensions is not supported by webpack. Use a loader instead.

WARNING in ./~/handlebars/lib/index.js
require.extensions is not supported by webpack. Use a loader instead.

ERROR in ./~/handlebars/lib/index.js
Module not found: Error: Cannot resolve 'file' or 'directory' ../dist/cjs/handlebars/compiler/printer in /home/abhisekp/MyProjects/JSApps/MadeWithLove-Webpack/node_modules/handlebars/lib
 @ ./~/handlebars/lib/index.js 9:14-64

ERROR in ./~/handlebars/lib/index.js
Module not found: Error: Cannot resolve module 'fs' in /home/abhisekp/MyProjects/JSApps/MadeWithLove-Webpack/node_modules/handlebars/lib
 @ ./~/handlebars/lib/index.js 17:11-24

ERROR in ./~/handlebars/lib/index.js
Module not found: Error: Cannot resolve 'file' or 'directory' ../dist/cjs/handlebars in /home/abhisekp/MyProjects/JSApps/MadeWithLove-Webpack/node_modules/handlebars/lib
 @ ./~/handlebars/lib/index.js 7:17-50 

My index.js

var handlebars = require('handlebars');

My package.json

  "dependencies": {
    "handlebars": "^4.0.5"
  }

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:6
  • Comments:27 (1 by maintainers)

github_iconTop GitHub Comments

213reactions
gilesbradshawcommented, Jul 1, 2016

I got round this with …

resolve: {
    alias: {
       handlebars: 'handlebars/dist/handlebars.min.js'
    }
}

in my webpack config

30reactions
catamphetaminecommented, Aug 13, 2018

This is retarded. This handlebars library should have fixed this bug. Yet they neglect and ignore.

The workaround is to replace:

import Handlebars from 'handlebars'

with:

import Handlebars from 'handlebars/dist/cjs/handlebars'
Read more comments on GitHub >

github_iconTop Results From Across the Web

handlebars.js - Error loading Handlebars partial with webpack ...
Webpack Config. I am using the handlebars-loader module, and have set both the rootRelative and helperDirs options appropriately (I think!):
Read more >
A Step By Step Guide To Using Handlebars With Your Node js ...
It's time for some Handlebars Yay! First off, we need to install the Handlebars dependency as follows: npm install express-handlebars --save. Then we...
Read more >
handlebars-error-parser - npm
The purpose of this module is to parse the Handlebars compile exceptions messages into a more useable format which can be used in...
Read more >
html-loader - webpack
webpack is a module bundler. Its main purpose is to bundle JavaScript files for usage in a browser, yet it is also capable...
Read more >
webpack + require handlebars error - Bountysource
I get the following error simply by using require handlebars. ▷ webpack --display-modules Hash: bdb0fe35e2f8bde783e5 Version: webpack ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found