How do I use javascript modules in django templates


My application is sending the data from views to template file in json format.
Since the template file will be very huge, so I am trying to split the js file into several modules.
But when I am trying to export data from first .js file to second .js file it’s giving error as ncaught SyntaxError: Export ‘compare_data’ is not defined in module .
What am I doing wrong here ?
Please help me out .
Thanks in Advance .

With Best Regards,
Anish Tulsyan .

This appears to me to be more of a JavaScript issue than a Django issue. Or more specifically, how you’re implementing those JavaScript modules.

Yes, Django would serve multiple JS files to the browser, but what happens in those files in the browser is completely outside Django’s control or influence.

1 Like


When I am executing a sample JS Application using import , export feature of JS , it works fine, but when the same thing is executed in the Django environment, it gives error.
Meanwhile I am trying for other options such as Webpack, which can solve my issue.
Please give your valuable feedback on this.

With Best Regards,
Anish Tulsyan .

You’re going to need to provide a sample of what you’re talking about here. Try to put together the smallest example of what’s not working.

Also, I’m going to need more clarification as to what you mean by

and what that means when you say

Also, what error are you receiving?

Note: When posting code here, enclose the code between lines of three backtick - ` characters. This means you’ll have a line of ```, then your code, then another line of ```.
Do not post images or screen captures of code. Copy/paste the code itself into your message, surrounded by the lines of ```.