I am trying to use handlebars in a client webpart using these posts:

https://n8d.at/blog/how-to-use-handlebars-in-sharepoint-framework-projects-spfx/ https://n8d.at/blog/first-handlebars-web-part-in-spfx/

in my gulp.js file, i have this code:

   additionalConfiguration: (generatedConfiguration)=> {
            { test: /\.hbs$/, loader: "handlebars-template-loader" } ); 
       return generatedConfiguration; 

I created a new file under config folder, called copy-static.assets.json, with this code inside:

{"includeExtensions": ["hbs"]}

i have the template on the same level as .ts webpart file, and i reference the template like this:

var compiled = require('./test.hbs'); 

am getting this error when I run gulp serve:

Module not found: Error: Can't resolve './test.hbs' using description file: C:\solutions\mywebpart\package.json . Field 'browser' doesn't contain a valid alias configuration.

Any idea how to solve this?


Try this instead in your gulpfile

const loaderRule = { "use": [{ "loader": "handlebars-template-loader" }], "test": /.hbs/ };

additionalConfiguration: (generatedConfiguration) => {

return generatedConfiguration;}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.