Can't find variable 'require' for custom js in app

Hi all,

I’m trying to create a custom chart in a page. When trying to load a js file (in assets, I have run bench build), I get:
ReferenceError: Can't find variable:require

Here is the js file being loaded.

frappe.pages['advanced-sales-funnel'].on_page_load = function(wrapper) {
	var page = frappe.ui.make_app_page({
		parent: wrapper,
		title: 'Advanced Sales Funnel',
		single_column: true
	frappe.require("assets/analytics/js/chartjs/chart.js"); //Reference Error

	wrapper.sales_funnel = new AdvancedSalesFunnel(wrapper);



frappe.require is now async (synchronous calls are deprecated in javascript)

1 Like

@rmehta okay, thank you!!

Is charts js integrated with erpnext because unable to find function .require?

I have been using chart.js by serving it in the public folder of a custom app, and then using hooks to provide it in head.

1 Like

Yes did that but not helping. Anything else that can be done. Are dev and prod mode paths separate?

@alec_ruizramon1 will be cool if you can share how you did it.

Basically following steps were done by me:

  1. Charts js was downloaded from github
  2. All files were extracted within public folder of my custom app
  3. All *.js file entries were added within build.json
  4. Main js file was also included within thereafter
  5. bench build was run inside frappe-bench directories finally


From front end when all js fles are being loaded by Frappe framework, while loading it throws an error in console output that: require is not a function, file chart.js
Error Line 1: require(‘./core/core.js’)();

Sorry for being brief yesterday.

Check here:
also here: Calendar view for sales opportunity? - #8 by ericmachine88

Chart.js is in the public folder there, and used in analytics/analytics/page/ (both pages). Essentially by hooking into the built chart.js all of the classes and functions are exposed for you to use in the rest of Frappe. It isn’t the most ‘efficient’ because you end up including it in head (every page) but it’s the simplest way so far.

1 Like