3

I'd like to import a Handlebars file as a template in my CRA project.

This is my current setup, adapted from React-App- Rewired won't add Babel Plugin, handlebars-loader, and customize-cra

config-overrides.js

const { override } = require('customize-cra');

const addHandleBarsLoader = config => {
    config.module.rules.push(
        { test: /\.handlebars$/, loader: "handlebars-loader" }
    );
    return config;
}

module.exports = override(
    addHandleBarsLoader
);

on the 3rd line here i get TypeError: template is not a function

const template = require("./test.handlebars");
console.log(template);
const htmlString = template(data);

console:

/static/media/test.a9cd7544.handlebars

package.json

  "scripts": {
    "start": "react-app-rewired start",
...

what am i doing wrong?

stuart
  • 1,785
  • 2
  • 26
  • 38
  • What is in `test.handlebars`? What does it export? – 76484 May 10 '20 at 13:46
  • @76484 it doesn't export anything, it's just a handlebars template, like `

    {{firstname}} {{lastname}}

    ` in https://handlebarsjs.com/examples/simple-expressions.html
    – stuart May 12 '20 at 15:02

0 Answers0