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

PostCSS on Windows does not work in directories with spaces #7333

Open
Heasummn opened this issue May 28, 2020 · 16 comments
Open

PostCSS on Windows does not work in directories with spaces #7333

Heasummn opened this issue May 28, 2020 · 16 comments
Labels
Milestone

Comments

@Heasummn
Copy link

Heasummn commented May 28, 2020

I'm still having this issue as of 5/28/2020. I've narrowed down the issue to here:

cmdArgs = []string{"--config", configFile}

Specifically, Go's exec.Command will treat spaces in parameters as different parameters, so they must be escaped or quoted if they have spaces.

I do not have the capabilities (right now) to get Hugo building on my machine, but I believe the simplest fix will be somehow escaping the string when passing it to exec.Command.

I believe, but cannot be certain, that this line should fix this issue:

configFile = `"` + configFile + `"`

This was closed as stale in #6283, but I think my solution should fix the problem.

@bep bep added the Bug label May 28, 2020
@bep bep added this to the v0.72 milestone May 28, 2020
@exprez135
Copy link

Perhaps it would be better to use the Quote() function in strconv, e.g.

configFile = strconv.Quote(configFile)

Though I'm not sure:

  1. If configFile will ever already be defined with quotes,

  2. If Quote() already checks if it's quoted (I don't think it does).

I could test some changes if someone has an example repository that uses PostCSS.

@bep bep modified the milestones: v0.72, v0.73 May 31, 2020
@Heasummn
Copy link
Author

I don't have a minimal failing example, but anything using the PostCSS hook that is built into Hugo should trigger this error.

{{ $css := resources.Get "css/main.css" }}
{{ $style := $css | resources.PostCSS }}

on your CSS file with PostCSS installed in a folder where postcss.config.js has a space in the path will not work.

@jmooring
Copy link
Member

Was postcss-cli installed globally (npm -g) or locally within the project directory?

@bep bep modified the milestones: v0.73, v0.74 Jun 23, 2020
@bep bep modified the milestones: v0.74, v0.75 Jul 13, 2020
@bep bep modified the milestones: v0.75, v0.76 Sep 14, 2020
@bep bep modified the milestones: v0.76, v0.77 Oct 6, 2020
@bep bep modified the milestones: v0.77, v0.78 Oct 30, 2020
@jannepeltola
Copy link

I can confirm this is still an issue. I have tried with both npm -g postcss-cli and a local installation.

@moorereason
Copy link
Contributor

Please share your hugo version output.

@jannepeltola
Copy link

Apologies for not doing that right away - here you go:

Hugo Static Site Generator v0.80.0/extended windows/amd64 BuildDate: unknown

It is the current version available on Chocolatey.

@jannepeltola
Copy link

If it's helpful, I can spend some time tomorrow to create a minimal repro? Unfortunately I probably won't have time to do it today.

@moorereason
Copy link
Contributor

A minimal demo repo is always helpful.

@jannepeltola
Copy link

So here's a repro.

With https://github.com/jannepeltola/hugo_issue_7333/, here's what happens:

C:\Users\Janne Peltola\Documents\GitHub\hugo_issue_7333>hugo env
Hugo Static Site Generator v0.80.0/extended windows/amd64 BuildDate: unknown
GOOS="windows"
GOARCH="amd64"
GOVERSION="go1.15.1"

C:\Users\Janne Peltola\Documents\GitHub\hugo_issue_7333>hugo server
Start building sites …
WARN 2021/01/14 15:54:56 found no layout file for "HTML" for kind "taxonomy": You should create a template file which matches Hugo Layouts Lookup Rules for this combination.
WARN 2021/01/14 15:54:56 found no layout file for "HTML" for kind "taxonomy": You should create a template file which matches Hugo Layouts Lookup Rules for this combination.
Built in 24 ms
Error: Error building site: POSTCSS: failed to transform "css/main.css" (text/css): 'C:\Users\Janne' is not recognized as an internal or external command,
operable program or batch file.

@moorereason
Copy link
Contributor

The underlying issue is that we're executing postcss.cmd. The cmd.exe command (which runs .bat and .cmd files) processes arguments differently than the rest of Windows. The os/exec package doesn't escape commands properly for cmd.exe usage.

Related upstream issues: golang/go#15566 golang/go#17149

@jannepeltola
Copy link

I see. Thanks for looking into this! I'll run Hugo inside Docker for the time being then until when (if...) the upstream issue gets resolved.

@Heasummn
Copy link
Author

It's a frustrating workaround, but it looks like adding quotes to the exec command should solve this issue. I can set up an environment to test that change.

@jannepeltola
Copy link

I can build and test a branch locally if you need a Windows environment!

@bep bep modified the milestones: v0.78, v0.83 Apr 23, 2021
@bep bep added this to the v0.118.0 milestone Aug 30, 2023
@bep bep modified the milestones: v0.118.0, v0.119.0 Sep 15, 2023
@bep bep modified the milestones: v0.119.0, v0.120.0 Oct 4, 2023
@bep bep modified the milestones: v0.120.0, v0.121.0 Oct 31, 2023
@bep bep modified the milestones: v0.121.0, v0.122.0 Dec 6, 2023
@bep bep modified the milestones: v0.122.0, v0.123.0, v0.124.0 Jan 27, 2024
@bep bep modified the milestones: v0.124.0, v0.125.0 Mar 4, 2024
@bep bep modified the milestones: v0.125.0, v0.126.0 Apr 23, 2024
@bep bep modified the milestones: v0.126.0, v0.127.0 May 15, 2024
@bep bep modified the milestones: v0.127.0, v0.128.0 Jun 8, 2024
@bep bep modified the milestones: v0.128.0, v0.129.0 Jun 21, 2024
@bep bep modified the milestones: v0.129.0, v0.131.0 Jul 22, 2024
@bep bep modified the milestones: v0.131.0, v0.133.0 Aug 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants