Skip to content

Script tags with relative url unexpected token < #577

Closed
@nycoliver

Description

@nycoliver

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions