Script tags with relative url unexpected token <
See original GitHub issueAdding 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:
- Created 7 years ago
- Reactions:1
- Comments:7 (6 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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.
Closing as this is fixed, and will be released in 0.5.0.