How to use unpkg url-join.js as <script src=…> import?


I’m trying to use urlJoin in my project. I’ve imported the library/script using <script> tag as the HTML is generated by Django.

<script src=""></script>

The problem is that I can’t use urlJoin function – the console says:

VM609:1 Uncaught ReferenceError: urlJoin is not defined
    at <anonymous>:1:1

The function is defined like this:

export default function urlJoin() {
  var input;

  if (typeof arguments[0] === 'object') {
    input = arguments[0];
  } else {
    input = [];

  return normalize(input);

Do you know how to use it?


The file is an ES6 module. See JavaScript modules on MDN.

You need to:

  • Mark the script where you use urlJoin as a module
  • import it into that script
  • Not have a separate <script> element to load urlJoin.


<script type="module">
  import urlJoin from ""; 
  const foo = urlJoin("some", "args"); 

Answered By – Quentin

Answer Checked By – Pedro (AngularFixing Volunteer)

Leave a Reply

Your email address will not be published.