0
votes

I'm trying to generate JS files using Mustache templating. I'm using NodeJS and want to create a JS file to make development during React projects faster. Now I've created below template:

export { default } from "./{{componentName}};

And I'm using it like this:

import index from "./templates/components/index.mustache";

  fs.appendFile(
    `./src/components/${componentType}s/${componentNameWithoutCapitals}/index.ts`,
    mustache.render(index, { componentName: componentNameWithoutCapitals }),
    (err) => err && console.log(err)
  );

I though Mustache would just render a string, and fill in the values which I pass via the object in the parameter. I get an error stating it can't find a module:

Error: Cannot find module './{{componentName}}'

Does someone know how I should proceed?

Can you provide a minimal reproducible example? Do you build the project ahead of time or do you render it just in time? - jabaa
You can install the project I created from NPM. Command: npm install propulse -g It's necesary to create a React app, and have the following folder structure: src/components/atoms. Then if you hit propulse add it prompts for what kind of component you'd like to generate. Select Atom, and give it a name. Then the error appears. - Ricardo de Vries