Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Script tags with relative url unexpected token < #577

Closed
nycoliver opened this issue Sep 4, 2016 · 7 comments
Closed

Script tags with relative url unexpected token < #577

nycoliver opened this issue Sep 4, 2016 · 7 comments
Milestone

Comments

@nycoliver
Copy link

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.

@gaearon
Copy link
Contributor

gaearon commented Sep 5, 2016

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.

@gaearon gaearon added this to the 1.0.0 milestone Sep 5, 2016
@nycoliver
Copy link
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.

@gaearon
Copy link
Contributor

gaearon commented Sep 6, 2016

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.

@gaearon gaearon reopened this Sep 6, 2016
@cloudmu
Copy link
Contributor

cloudmu commented Sep 9, 2016

Related: #573

@gaearon
Copy link
Contributor

gaearon commented Sep 22, 2016

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!

@gaearon gaearon modified the milestones: 0.5.0, 1.0.0 Sep 22, 2016
@gaearon
Copy link
Contributor

gaearon commented Sep 22, 2016

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

@gaearon gaearon closed this as completed Sep 22, 2016
@gaearon
Copy link
Contributor

gaearon commented 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.

@lock lock bot locked and limited conversation to collaborators Jan 22, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants