Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using Handlebars with webpack warning require.extentions not supported #953

Closed
stevewillard opened this issue Feb 4, 2015 · 11 comments
Closed

Comments

@stevewillard
Copy link

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.

@kpdecker
Copy link
Collaborator

kpdecker commented Feb 5, 2015

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.

@kpdecker kpdecker closed this as completed Feb 5, 2015
@trusktr
Copy link

trusktr commented Apr 21, 2015

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?

@trusktr
Copy link

trusktr commented Apr 21, 2015

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.

@seeliang
Copy link

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

@kpdecker
Copy link
Collaborator

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

@seeliang
Copy link

Thanks @kpdecker ,
i will try that

@kpdecker
Copy link
Collaborator

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

@blakedietz
Copy link

blakedietz commented Aug 15, 2016

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

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

Thanks @kpdecker.

@seyfer
Copy link

seyfer commented Jun 14, 2018

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 pcardune/handlebars-loader#110 (comment)

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',
};

@danieldanielecki
Copy link

const nodeExternals = require('webpack-node-externals');
module.exports = {
  externals: [nodeExternals()]
}

Also does works.

@richardebrain
Copy link

richardebrain commented Feb 23, 2024

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

were you able to fix handlebars is not a function , i am getting this.viewEngine.renderView is not a function and i am using nextjs approuter

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants