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

Error loading module with assets on Windows #751

Closed
rmcshane opened this issue Sep 1, 2015 · 6 comments
Closed

Error loading module with assets on Windows #751

rmcshane opened this issue Sep 1, 2015 · 6 comments

Comments

@rmcshane
Copy link

rmcshane commented Sep 1, 2015

Loading a module with assets on Windows fails. This is caused by line 2633:

if (typeof window != 'undefined' && typeof document != 'undefined' && window.location)
  var windowOrigin = location.protocol + '//' + location.hostname + (location.port ? ':' + location.port : '');

In this case, location.protocol = 'file:' which causes problems at line 2687:

if (windowOrigin && address.substr(0, windowOrigin.length) === windowOrigin) {
  address = address.substr(windowOrigin.length);
  dirname = dirname.substr(windowOrigin.length);
}

Which causes address = '/c:/path/to/module'. This eventually causes the module to treat __dirname = 'c:\c:\path\to\module' and loading assets fails.

The following change fixes this issue at line 2633:

if (typeof window != 'undefined' && typeof document != 'undefined' && window.location && location.hostname)
  var windowOrigin = location.protocol + '//' + location.hostname + (location.port ? ':' + location.port : '');
@guybedford
Copy link
Member

Thanks for sharing. Does the change:

if (typeof window != 'undefined' && typeof document != 'undefined' && window.location)
  var windowOrigin = location.protocol + '//' + (location.protocol == 'file' && location.hostname[0] != '/' ? '/' : '') + location.hostname + (location.port ? ':' + location.port : '');

also work for you here?

@guybedford guybedford added the bug label Sep 2, 2015
@rmcshane
Copy link
Author

rmcshane commented Sep 3, 2015

That nearly fixes it. The protocol includes a colon, so adding that to the check for a file protocol fixes the issue I noticed:

if (typeof window != 'undefined' && typeof document != 'undefined' && window.location)
  var windowOrigin = location.protocol + '//' + (location.protocol == 'file:' && location.hostname[0] != '/' ? '/' : '') + location.hostname + (location.port ? ':' + location.port : '');

This problem doesn't happen on Mac, or at least doesn't in my environment.

@guybedford
Copy link
Member

Excellent, thanks I've included the fix.

@guybedford guybedford reopened this Sep 4, 2015
guybedford added a commit that referenced this issue Sep 6, 2015
@guybedford
Copy link
Member

The fix wasn't quite right - I've corrected it in 91b7bc0. Do let me know if you still have any problems here.

@guybedford
Copy link
Member

NB this should be ported for 0.18 before the 0.19 release.

@guybedford
Copy link
Member

Released in 0.19.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants