question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Script tags with relative url unexpected token <

See original GitHub issue

Adding a script tag with a relative src throws SyntaxError: Unexpected token <

To reproduce, create-react-app then add this line to index.html: <script type="text/javascript" src="test.js"></script>

File should look like this:

<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="shortcut icon" href="./src/favicon.ico">
    <title>React App</title>
    <script type="text/javascript" src="test.js"></script>
  </head>
  <body>
    <div id="root"></div>
    <!--
      This HTML file is a template.
      If you open it directly in the browser, you will see an empty page.

      You can add webfonts, meta tags, or analytics to this file.
      The build step will place the bundled scripts into the <body> tag.

      To begin the development, run `npm start` in this folder.
      To create a production bundle, use `npm run build`.
    -->
  </body>
</html>

npm start and chrome will throw index.js:1 Uncaught SyntaxError: Unexpected token <

If I replace the src with an absolute url, for example https://npmcdn.com/ipfs-api/dist/index.js, the error goes away.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
gaearoncommented, Sep 23, 2016

This is now supported in 0.5.0.

Read about using the new public folder.

See also migration instructions and breaking changes in 0.5.0.

0reactions
gaearoncommented, Sep 22, 2016

Closing as this is fixed, and will be released in 0.5.0.

Read more comments on GitHub >

github_iconTop Results From Across the Web

SyntaxError: Unexpected token in JavaScript | bobbyhadz
Make sure that your script tags point to a valid path and try renaming all your files to lowercase letters only. Sometimes the...
Read more >
Unexpected token < in first line of HTML - Stack Overflow
Url.AbsoluteUri. ... In my case when I changed script attribute src to correct path error got fixed. <script src="correct path"> </script>.
Read more >
Javascript problems after uploading to server - Laracasts
I changed all relative urls to full urls and still they wouldn't work. Not really sure what to do here. ... Uncaught SyntaxError:...
Read more >
uncaught syntaxerror unexpected token javascript - You.com
In my case ( Webpack v.5 + React ) it was happen on pages with 2nd or more nested level of pages. All...
Read more >
Uncaught SyntaxError: Unexpected token < console error
i used relative path instead of the absolute path. this how i solved it <script src="{{ asset('js/app.js') }}"></script>.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found