How to use Handlebars in Angular 12

Viewed 765

I used to be able to use Handlebars in Angular 11 but since I updated to Angular 12 I'm getting the following errors:

./node_modules/handlebars/lib/index.js:25:2-9 - Warning: Critical dependency: require function is used in a way in which dependencies cannot be statically extracted
./node_modules/handlebars/lib/index.js:23:38-45 - Error: Module not found: Error: Can't resolve '.' in '/node_modules/handlebars/lib'

I'm importing Handlebars like

import * as handlebars from 'handlebars';

I have tried to add Handlebars to the angular.json as following but nothing seems to be working.

"node_modules/handlebars/dist/handlebars.min.js"
1 Answers

Importing from handlebars/dist/amd/handlebars or handlebars/dist/cjs/handlebars works but the handlebars package has to be added to the allowedCommonJsDependencies.

Related