Skip to content

Script tags with relative url unexpected token < #577

Closed

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.

Activity

  1. gaearon commented on Sep 5, 2016

    @gaearon
    Contributor

    What are you trying to do? This was never officially supported. It accidentally worked in versions before 0.4.0 but only worked in development.

    Normally you should just import scripts instead in src/index.js. If there is some reason why this doesn't satisfy your use case, please describe it here so we can have a better idea of your use case and can address it in a future version. Thanks!

    Related: #573 #551.

  2. added this to the 1.0.0 milestone on Sep 5, 2016
  3. nycoliver commented on Sep 6, 2016

    @nycoliver
    Author

    I'm using a module (js-ipfs-api) which requires fs shims to run in browser and would prefer not to eject. I'll host it remotely for now and wait for its webpack incompatibilities to be resolved.

  4. gaearon commented on Sep 6, 2016

    @gaearon
    Contributor

    Let's keep this open for now. Maybe we can configure Webpack to include more sensible shim for fs. I've seen this problem a couple of times and I think there was some solution.

  5. reopened this on Sep 6, 2016
  6. cloudmu commented on Sep 9, 2016

    @cloudmu
    Contributor

    Related: #573

  7. gaearon commented on Sep 22, 2016

    @gaearon
    Contributor

    I drafted a proposal to solve this in #703. Unless we find some fatal flaws, it should come out in 0.5.0. Let me know what you think!

  8. modified the milestones: 0.5.0, 1.0.0 on Sep 22, 2016
  9. gaearon commented on Sep 22, 2016

    @gaearon
    Contributor

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

  10. gaearon commented on Sep 23, 2016

    @gaearon
    Contributor

    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.

  11. locked and limited conversation to collaborators on Jan 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions