Parcel: Parcel adds a / before sourcemap paths -> Firefox can't read them

Created on 27 Oct 2018  路  3Comments  路  Source: parcel-bundler/parcel

馃悰 bug report

I'm working on a webextension for Firefox. The code is written in Typescript.
But parcel generates sourcemap paths that are not parsed correctly by Firefox.
The paths look like this:
//# sourceMappingURL=/content2.map

without the slash in from of content2.map, the path can be read by Firefox.
This problem occurs only for sourcefiles within folders.

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

My configuration is minimal, just Typescript and Parcel. To let you reproduce the problem, I set up a git repository, see below.

馃 Expected Behavior

Parcel shouldn't generate that slash.

馃槸 Current Behavior

Well, currently it generates it :P

馃捇 Code Sample

Here is a repository that can reproduce the problem:
https://github.com/lhk/nested_sourcemaps

This sample contains two scripts. One is in src/, the other is in src/content. Both scripts print something to the console, which makes them easy to find.
The master branch contains no parcel and shows you how the code works correctly:

git clone https://github.com/lhk/nested_sourcemaps
cd nested_sourcemaps
npm install
tsc

Now you can load src/manifest.json into Firefox. Open any website, open the developer console, reload the website, you will see two logs from the two scripts. Firefox automatically recognizes them as typescript :)

Now you switch to the parcel branch

git reset --hard
git clean -xdf
git checkout parcel_branch
npm install
parcel build src/manifest.json

Same procedure as above, load the plugin into Firefox. Now you have to use the manifest from dist/manifest.json.

Again, you can see two console logs. But for the script in src/content, the sourcemap can't be parsed.

If I edit this file manually and change the last line from:
//# sourceMappingURL=/content2.map
to
//# sourceMappingURL=content2.map
Then it works as expected.

馃實 Your Environment

| Software | Version(s) |
| ---------------- | ---------- |
| Parcel | 1.10.3
| Node | v8.12.0
| npm/Yarn | npm 6.4.1
| Operating System | ubuntu 18.04.01 64bit
| Firefox | 63

Waiting Question

Most helpful comment

@lhk use 鈥攑ublic-url ./

Sent with GitHawk

All 3 comments

This is very similar to #1753

Curiously, in the other case the / is missing, while I want to get rid of it.

@lhk use 鈥攑ublic-url ./

Sent with GitHawk

Thanks, that solves it.

Was this page helpful?
0 / 5 - 0 ratings