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

🐛 sourceMappingURL is not relative to the mapped file #1028

Closed
xthezealot opened this issue Mar 19, 2018 · 7 comments
Closed

🐛 sourceMappingURL is not relative to the mapped file #1028

xthezealot opened this issue Mar 19, 2018 · 7 comments
Labels

Comments

@xthezealot
Copy link

🐛 Bug report

The generated sourceMappingURL is a mix of relative and absolute path.
Relative to the source file directory, but absolute as it starts with /.

🎛 Configuration

package.json

"scripts": {
  "watch": "parcel watch static/app.js -d static/build"
}

🤔 Expected Behavior

//# sourceMappingURL=app.map

😯 Current Behavior

//# sourceMappingURL=/build/app.map

💁 Possible Solution

Use the relative path to the map file (actually, just the file name as it's inside the same directory).

🔦 Context

When my server is configured to serve static (or "public") files under /static/<filepath>, the URL of app.map is in fact /static/build/app.map.

So the sourceMappingURL=/build/app.map is wrong and results in a "404 Not found" in the browser.

🌍 Environment

  • Parcel 1.6.2
  • Node 9.8.0
  • NPM 5.7.1
  • macOS 10.13.3 (17D102)
@davidnagli
Copy link
Contributor

We write that sourcemap link comment here:

await this.dest.write(
`\n//# sourceMappingURL=${urlJoin(
this.options.publicURL,
path.basename(this.bundle.name, '.js') + '.map'
)}`

I guess your publicURL option is set to /build which is why it's returning that path. If the publicURL is set to / then you should get the behavior you're looking for (as far as I can tell).


For a quick fix, try setting the --public-url flag to / manually:

"scripts": {
  "watch": "parcel watch static/app.js -d static/build --public-url /"
}

However this should fix it self when PR #838 lands, since it makes / the default public URL 😃

@xthezealot
Copy link
Author

I didn't set the publicURL manually.
Now, if I use --public-url /, the sourceMappingURL will be /app.map, which is also incorrect because it's in fact /static/build/app.map.

My project structure is:

/
├── static/          # public directory
│   ├── build/       # files built by Parcel
│   │   ├── app.js
│   │   └── app.map
│   └── app.js       # original file
├── package.json
└── server.js

The solution is rather --public-url . (simply, a real relative path).

Thanks for steering me to the this flag. 👍

@DeMoorJasper
Copy link
Member

Well as this is probably more related to #838 than sourcemaps I'll close this down as it's a duplicate and appears to be solved in your case

@cphoover
Copy link

@ArthurWhite did you ever find a fix for this?

@xthezealot
Copy link
Author

@cphoover
As said in my last message, the --public-url flag set to . (relative path) may be a solution:

parcel watch static/app.js -d static/build --public-url .

@SCWR
Copy link

SCWR commented Dec 18, 2018

Thanks,
Is there any problem with this?
Css map file generation but one less sentence in css compressed file
/*# sourceMappingURL=./common.map */

aalekseev added a commit to Good-Habits/good-habits-webapp that referenced this issue Oct 29, 2019
So, there is a bug in the parcel-bundler. I was generating the
sourcemap with a wrong path, but in reality it should've been
relative to the client code. I.e. my bundle in `/public/client.js`
but inside that file the last string is a link to the source maps
and it was `/client.js.map`, and of course Firefox was unable to
find that file.

parcel-bundler/parcel#1028
@Alex-Horlock
Copy link

Hi, this issue has bugged me for a round 2 hours today... a complete novice to parcel i thought it was my problem as many tutorials suggest putting your output in a 'dist' folder rather than loose at the root. In the end setting '--public-url /dist/' fixed it for me. Admittedly it is in the docs (https://parceljs.org/cli.html) but I feel like some sort of warning might help. e.g in the minified file it could say 'to change this set the public url..'. Thanks.

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

6 participants