# Bad source map path in subfolder install

**URL:** https://meta.discourse.org/t/bad-source-map-path-in-subfolder-install/130241
**Category:** Bug
**Created:** [October 4, 2019, 12:28pm UTC](https://meta.discourse.org/t/bad-source-map-path-in-subfolder-install/130241 "2019-10-04T12:28:19Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![RGJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rgj/32/523185_2.png) [@RGJ](https://meta.discourse.org/u/RGJ)
#### Post date: [October 4, 2019, 12:28pm UTC](https://meta.discourse.org/t/bad-source-map-path-in-subfolder-install/130241/1 "2019-10-04T12:28:19Z")

</div>

My subfolder install kept giving errors in Firefox console about the fact that it is unable to find source maps.

`Source map error: request failed with status 404 Resource URL: [https://redacted.com/community/assets/admin-…1d82fc1b0c7d1f24b7b71256a4eb4860f1aa96444925a361d8c24425c.js](https://redacted.com/community/assets/admin-e1c3cbc1d82fc1b0c7d1f24b7b71256a4eb4860f1aa96444925a361d8c24425c.js) Source Map URL: /assets/admin-e1c3cbc1d82fc1b0c7d1f24b7b71256a4eb4860f1aa96444925a361d8c24425c.js.map`

As you can see, the `/community` path prefix is missing from the source map URL.

So I did a little digging.

`lib/tasks/assets.rake` does this:

```plaintext
  assets = cdn_relative_path("/assets")
  source_map_root = assets + ((d = File.dirname(from)) == "." ? "" : "/#{d}")

```

Now `cdn_relative_path` in `lib/global_path.rb` looks like this.

```
module GlobalPath
  def path(p)
    "#{GlobalSetting.relative_url_root}#{p}"
  end

  def cdn_path(p)
    GlobalSetting.cdn_url.blank? ? p : "#{GlobalSetting.cdn_url}#{path(p)}"
  end

  def upload_cdn_path(p)
    if SiteSetting.Upload.s3_cdn_url.present?
      p = Discourse.store.cdn_url(p)
    end

    (p =~ /^http/ || p =~ /^\/\//) ? p : cdn_path(p)
  end

  def cdn_relative_path(path)
    if (cdn_url = GlobalSetting.cdn_url).present?
      URI.parse(cdn_url).path + path
    else
      path
    end
  end

```

As you can see, both `cdn_path` and `upload_cdn_path` eventually call the `path` method which makes sure that the subfolder is being prefixed. However, `cdn_relative_path` does not call the `path` method, it just returns its parameter (called… `path`).

BTW I think cdn\_path needs to return `path(p)` in the middle part of the ternary as well?

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [October 5, 2019, 12:54pm UTC](https://meta.discourse.org/t/bad-source-map-path-in-subfolder-install/130241/2 "2019-10-05T12:54:57Z")

</div>

@sam is the expert on source maps

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [October 8, 2019, 4:07am UTC](https://meta.discourse.org/t/bad-source-map-path-in-subfolder-install/130241/3 "2019-10-08T04:07:49Z")

</div>

@david has fussed with this in the past, but yeah getting the paths right for CDN + subfolder is not easy. I am open to a PR that fixes it provided this is very targeted at your magic combo and does not regress any places that work now.

---

<div class="post-metadata">

### Author: ![atom](https://avatars.discourse-cdn.com/v4/letter/a/85f322/32.png) [@atom](https://meta.discourse.org/u/atom)
#### Post date: [September 18, 2020, 12:39pm UTC](https://meta.discourse.org/t/bad-source-map-path-in-subfolder-install/130241/4 "2020-09-18T12:39:11Z")

</div>

@sam Do we have some solutions for this issue with a wrong source map? I have the same problem with subfolder install and Fastly CDN

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [September 24, 2020, 6:08am UTC](https://meta.discourse.org/t/bad-source-map-path-in-subfolder-install/130241/5 "2020-09-24T06:08:36Z")

</div>

My recommendation is just to wait a while, we are moving to ember CLI which will replace this entire pipeline.

---

<div class="post-metadata">

### Author: ![bu1der](https://avatars.discourse-cdn.com/v4/letter/b/f6c823/32.png) [@bu1der](https://meta.discourse.org/u/bu1der)
#### Post date: [February 8, 2021, 10:38am UTC](https://meta.discourse.org/t/bad-source-map-path-in-subfolder-install/130241/6 "2021-02-08T10:38:55Z")

</div>

@sam When are we moving to ember CLI? We have the same problem with subfolder install and Fastly CDN

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [February 9, 2021, 12:35am UTC](https://meta.discourse.org/t/bad-source-map-path-in-subfolder-install/130241/7 "2021-02-09T00:35:07Z")

</div>

This move is in progress, you can already develop on local using ember cli, a few more months out.

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [March 1, 2022, 4:59am UTC](https://meta.discourse.org/t/bad-source-map-path-in-subfolder-install/130241/9 "2022-03-01T04:59:43Z")

</div>

I believe this should be sorted with ember-cli? @david would you know if that is the case?

---

<div class="post-metadata">

### Author: ![david](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/david/32/157490_2.png) [@david](https://meta.discourse.org/u/david)
#### Post date: [March 1, 2022, 10:42am UTC](https://meta.discourse.org/t/bad-source-map-path-in-subfolder-install/130241/10 "2022-03-01T10:42:10Z")

</div>

Yeah I’ve made a number of source-map improvements over the last few weeks, which apply to both ‘legacy’ and Ember-CLI pipelines.

Just checked one of our hosted subfolder sites on tests-passed, and things seem to be working much better 👌

---

<div class="post-metadata">

### Author: ![david](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/david/32/157490_2.png) [@david](https://meta.discourse.org/u/david)
#### Post date: [March 14, 2022, 8:00am UTC](https://meta.discourse.org/t/bad-source-map-path-in-subfolder-install/130241/11 "2022-03-14T08:00:21Z")

</div>

This topic was automatically closed after 12 days. New replies are no longer allowed.
