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

Loading libraries via script src doesn't create the global #2422

Closed
dandv opened this issue Dec 16, 2018 · 3 comments
Closed

Loading libraries via script src doesn't create the global #2422

dandv opened this issue Dec 16, 2018 · 3 comments
Labels

Comments

@dandv
Copy link
Contributor

dandv commented Dec 16, 2018

🐛 bug report

Loading via script src a local copy of a library doesn't create the window global that it does if the library were loaded from its absolute URL, or if the HTML file were open directly in the browser via file:///.

🎛 Configuration (.babelrc, package.json, cli command)

Zero-config.

🤔 Expected Behavior

I expect that the code sample below works the same whether it's loaded by the browser via file:///, or by parcel index.html. The sample simply loads jQuery via script src in the HTML and logs $.

😯 Current Behavior

(index):6 Uncaught ReferenceError: $ is not defined

💁 Possible Solution

Including the full URL in script src works:

<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" type="text/javascript"></script>

🔦 Context

The use case is obviously not jQuery, but loading Pro/paid libraries that need to be downloaded separately and aren't available via npm or CDNs.

💻 Code Sample

Download/cURL/wget https://code.jquery.com/jquery-3.3.1.slim.min.js in the same directory as index.html.

<html>
<head>
  <script src="jquery-3.3.1.slim.min.js" type="text/javascript"></script>
</head>
<body>
<script>
console.log($);
</script>
</body>
</html>

🌍 Your Environment

Software Version(s)
Parcel commit 7a540fc
Node 11.3.0
npm/Yarn 6.5.0
Operating System Ubuntu Linux 16.04
@kirillrogovoy
Copy link
Contributor

As far as I understand, Parcel expects you to reference your dependencies using relative FS paths, just like you require files in Node (const moduleX = require('./module-x.js')).

So in your case you're supposed to write

<script src="./jquery-3.3.1.slim.min.js" type="text/javascript"></script>

or whatever the path would be relatively to your index.html.

@mischnic
Copy link
Member

mischnic commented Jan 7, 2019

Duplicate of #333

@mischnic mischnic marked this as a duplicate of #333 Jan 7, 2019
@mischnic mischnic closed this as completed Jan 7, 2019
@flkx
Copy link

flkx commented Dec 3, 2020

pffff Parcel is super light bla bla bla but ... it doesn't work !!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants