Handlebars.js: Using Handlebars with webpack warning require.extentions not supported

Created on 4 Feb 2015  ·  10Comments  ·  Source: handlebars-lang/handlebars.js

Is there any way to remove or disable these warnings when loading Handlebars with Webpack?

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.

Most helpful comment

@kpdecker @seeliang: I just want to let others know that aliasing handlebars works.

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

Thanks @kpdecker.

All 10 comments

I would recommend precompiling using something like handlebars-loader and utilizing the handlebars/runtime module. Otherwise you should use one of the client-side builds via bower as those do not have any of this node-specific code.

I would recommend precompiling using something like handlebars-loader and utilizing the handlebars/runtime module.

@kpdecker How would we do that? I've got handlebars 1.3.0 and handlebars-loader ^1.0.2 both installed, then I have an AMD module that looks like this:

define([
  'hbs!path/to/template' // path/to/template.hbs
],
function(template) {
  // ...
});

and in webpack config I have:

{
  resolveLoader: {
    fallback: path.join(__dirname, 'node_modules'),
    alias: {
      'hbs': 'handlebars-loader'
    }
  },
}

so that the hbs! maps to the handlebars-loader. Then when I run webpack, I get those familiar warnings:

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

What am I missing? What am I supposed to do with handlebars/runtime?

Alright, so adding an alias for handlebars seems to have gotten rid of the warnings:

{
  resolve: {
    modulesDirectories: ['node_modules', 'src'],
    fallback: path.join(__dirname, 'node_modules'),
    alias: {
      'handlebars': 'handlebars/runtime.js'
    }
  },
  resolveLoader: {
    fallback: path.join(__dirname, 'node_modules'),
    alias: {
      'hbs': 'handlebars-loader'
    }
  }
}

That seems to be the trick, but I still have other errors to figure out before anything can even run, then I'll know if this works.

Hi , @kpdecker,

thank you for your feedback.
it's kind of working.

i am having the same issue, it's quite interesting that if i add @trusktr 's "resolve" section ('handlebars/runtime.js') run webpack and i will get the "Handlebars.compile is not a function"

Did i missed anything?

many thanks

The runtime does not include the compiler. You'll need to precompile your template, which is the best practice. If you absolutely need to compile templates on the client and are fine with the cost (startup and file size), then you'll want to alias handlebars to something like handlebars/dist/handlebars.js

Thanks @kpdecker ,
i will try that

I've also filed #1102 to see if this can be made cleaner for people who do want the whole runtime.

@kpdecker @seeliang: I just want to let others know that aliasing handlebars works.

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

Thanks @kpdecker.

For others looking here

This is the best solution I have found
https://github.com/valtech-nyc/brookjs/blob/master/packages/brookjs/webpack.config.js#L39-L43
here https://github.com/pcardune/handlebars-loader/issues/110#issuecomment-358681867

Thanks to @mAAdhaTTah

UPD:

//fix handlebars warnings
config.resolve.alias = {
    ...config.resolve.alias,
    'handlebars/runtime': 'handlebars/dist/cjs/handlebars.runtime',
    'handlebars': 'handlebars/dist/cjs/handlebars.runtime',
};
const nodeExternals = require('webpack-node-externals');
module.exports = {
  externals: [nodeExternals()]
}

Also does works.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

novwhisky picture novwhisky  ·  4Comments

rizen picture rizen  ·  6Comments

amirzandi picture amirzandi  ·  7Comments

morgondag picture morgondag  ·  5Comments

nknapp picture nknapp  ·  3Comments