ember-auto-import icon indicating copy to clipboard operation
ember-auto-import copied to clipboard

fails to build when rootURL undefined

Open BryanCrotaz opened this issue 3 years ago • 5 comments

function ensureTrailingSlash(url: string): string {
  if (url[url.length - 1] !== '/') {    // <-------------- Cannot read property 'length' of undefined
    url = url + '/';
  }
  return url;
}

This is called from publicAssetURL which uses rootURL from the project or addon. Project had baseURL defined but not rootURL.

BryanCrotaz avatar Jan 29 '22 18:01 BryanCrotaz

Suggested change:

 publicAssetURL(): string {
    if (this.isAddon) {
      throw new Error(`bug: only the app should control publicAssetURL`);
    }
    return ensureTrailingSlash(
      this.autoImportOptions?.publicAssetURL ??
//        ensureTrailingSlash((this._parent as any).config().rootURL) + 'assets/'
        ensureTrailingSlash((this._parent as any).config().rootURL ?? '/') + 'assets/'
    );
  }

BryanCrotaz avatar Jan 29 '22 19:01 BryanCrotaz

Yeah, I think it's OK to default rooURL to / if it's unset.

I would consider it a grey area whether not setting it is really supported, but it happens to work in classic builds so we can follow suit.

ef4 avatar Jan 30 '22 22:01 ef4

Maybe add a deprecation warning. This is most likely a hangover from a very old app that's been upgraded

BryanCrotaz avatar Jan 31 '22 07:01 BryanCrotaz

How did you solve this? I'm on v2.7.2.

If I go to node_modules and edit the package.js file, things work. But then how do I build it?

yandiro avatar Jan 03 '24 06:01 yandiro

hello @yandiro I can tell you about my use case for not having a rootURL set or more precisely for having it be a relative one to where the build is deployed what I ended up with is rootURL: '' AND when environment === 'test' fall back onto ENV.rootURL = '/'; or your /tests won't work correctly

void-mAlex avatar Jan 03 '24 09:01 void-mAlex