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

Incorrect source paths generated in the CSS when used under Windows. #15

Closed
allanbjorklund opened this issue Jan 14, 2016 · 20 comments
Closed

Comments

@allanbjorklund
Copy link

When using this under Windows, the CSS generated has incorrect source paths. I tracked the problem down to this function:

function makeFontFace(request) {
request.name = path.join(options.fontsDir, request.name);
return template
.replace(/$(\w )/g, function (m, name) { return request[name]; });
}

The error is that 'path' will use the local system's path separator when joining path elements. The end result is that the web server treats the Windows '' as an escape character, and returns that there is no such file when trying to access the woff file. (Even when running under Windows.)

The fix is to change the path join statement to the following.

request.name = path.posix.join(options.fontsDir, request.name);

This will always use the '/' when joining the path elements, and will produce the correct source URL path in the CSS.

@battlesnake
Copy link
Owner

Thanks, done

@gyretech
Copy link

This change causes the following error:

request.name = path.posix.join(options.fontsDir, request.name);
                                          ^
TypeError: Cannot call method 'join' of undefined

@battlesnake
Copy link
Owner

You're probably using an old version of Node, path.posix.join is in the spec: https://nodejs.org/api/path.html#path_path_posix

@gyretech
Copy link

gyretech commented Apr 18, 2016

Is v5.10.1 old? When I replace "path.posix.join" with "path.join" it works.

@battlesnake
Copy link
Owner

v5.10.1 isn't old, however path.posix.join is in the official docs, and path.join will break on Windows (a previous PR changed it to the POSIX version). Since the POSIX version is in the official docs, I'm not going to make any changes here.

Are you definitely loading the built-in path module and not some external one?

@battlesnake
Copy link
Owner

It works for me using Node v5.10.1 and NPM v3.8.6 on Arch Linux - what distro are you using?

@gyretech
Copy link

I am on Windows 10 and it only works when I remove posix.

@gyretech
Copy link

F:\Website\node_modules\gulp-google-webfonts\index.js:209
                request.name = path.posix.join(options.fontsDir, request.name);
                                          ^
TypeError: Cannot call method 'join' of undefined
    at makeFontFace (F:\Website\node_modules\gulp-google-webfonts\index.js:209:31)
    at Array.map (native)
    at generateFontCss (F:\Website\node_modules\gulp-google-webfonts\index.js:204:6)
    at parseCss (F:\Website\node_modules\gulp-google-webfonts\index.js:191:4)
    at fn (F:\Website\node_modules\gulp-google-webfonts\node_modules\async\lib\async.js:638:34)
    at Object._onImmediate (F:\Website\node_modules\gulp-google-webfonts\node_modules\async\lib\async.js:554:34)
    at processImmediate [as _immediateCallback] (timers.js:345:15)
Process terminated with code 8.

@battlesnake
Copy link
Owner

Ok - I've no idea then. I'll leave the .posix. in, as it's documented and works on Linux and whatever version of Windows the person who originally added it uses.

@battlesnake
Copy link
Owner

Are you definitely loading the built-in path module and not some external one?

@gyretech
Copy link

"dependencies": { "bower": "^1.7.7", "del": "^2.2.0", "path": "^0.12.7" },

@battlesnake
Copy link
Owner

You're probably not using the built-in if it's listed in package.json dependencies.

@gyretech
Copy link

ok, let me correct that.

@gyretech
Copy link

Same thing.

@battlesnake
Copy link
Owner

Have you removed the external path module completely or just from package.json?

@battlesnake
Copy link
Owner

When you've removed it completely, the plugin will work, as you're using the same version of Node as me

@gyretech
Copy link

I ran npm uninstall path.

@gyretech
Copy link

I also ran npm -g uninstall path --save

@gyretech
Copy link

gyretech commented Apr 23, 2016

So I am the only one having this issue?
I am on Windows
request.name = path.join(options.fontsDir, request.name); works perfectly fine

But request.name = path.posix.join(options.fontsDir, request.name); gives me an error cannot call method join.

@battlesnake
Copy link
Owner

Apparently. If you were loading the built-in path module and it's up to date then you wouldn't have this problem. Somewhere, you have a 3rd-party or out-dated version of it which is being loaded. Do any of the project's parent folders also contain a node_modules folder?

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

3 participants