Parcel: Parcel output refers to a nonexistent js file, when referring to other html file

Created on 13 Mar 2019  路  5Comments  路  Source: parcel-bundler/parcel

Choose one: This is a 馃悰 bug report


Inside my index.html I have an anchor href that refers to other html in other folder. For some reason Parcel output includes a script tag to a js file that cannot be found. Of course, the browser fails to load the generated page because of that.

馃帥 Configuration (.babelrc, package.json, cli command)

index.html
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
<title>Home Page</title>
</head>

<body>
I agree to all the <a href="docs/terms.html" target="_blank">terms of use</a>
</body>

</html>

docs/terms.html:

<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
<title>Terms of Use</title>
</head>

<body style="background-color: yellow">
Terms of Use:
</body>

</html>

CLI command
parcel index.html

馃 Expected Behavior

Valid output of index.html, that referes correctly to docs/terms.html

馃槸 Current Behavior

In the generated index.html file, the header looks like this:

<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>Home Page</title>
<script src="/terms.js"></script> Invalid location!
</head>

the output includes also docs folder with terms.html and terms.js, that contains Parcel code. However the script src above is invalid, and the page fails to load in the browser because of that.

馃拋 Possible Solution

Refer correctly to the generated js file.

馃敠 Context

Testing Parcel for building static site.

馃捇 Code Sample

Provided above.

馃實 Your Environment

| Software | Version(s) |
| ---------------- | ---------- |
| Parcel CLI | 1.12.1
| Node | 10.13.0
| npm/Yarn | 6.4.1
| Operating System | Windows 10

Bug Confirmed Bug

Most helpful comment

--no-hmr should be a workaround if you don't need HMR.

All 5 comments

Same problem with Parcel 1.12.3, but it works in version 1.9.7

I'm having the exact same issue in my project with Parcel 1.12.3, Node 10.15.3, and Yarn 1.15.2, on Windows 7. I can confirm that the issue does not happen in Parcel 1.9.7

I've noticed that this only happens when running parcel or parcel watch but _not_ parcel bundle

In the meantime, downgrading to Parcel 1.9.7 appears to work for me.

--no-hmr should be a workaround if you don't need HMR.

parcel build index.html --public-url ./ solved referring problem for me with Parcel 1.12.3

Confirm bug:

parcel --help build frontend/src/*/*_index.html --public-url /static

creates a html with non existent js:

<script src="/static/c1da89634367459316bb0791186cb047.js">

while

parcel --help build frontend/src/*/*_index.html --public-url ./static

creates html with wrong (relative) path

<script src="static/main.553dfdc2.js"></script>

Fixing the path by hand to

<script src="/static/main.553dfdc2.js"></script>

works

Was this page helpful?
0 / 5 - 0 ratings