Open Heasummn opened 4 years ago
Perhaps it would be better to use the Quote() function in strconv, e.g.
configFile = strconv.Quote(configFile)
Though I'm not sure:
If configFile will ever already be defined with quotes,
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.
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.
Was postcss-cli installed globally (npm -g
) or locally within the project directory?
I can confirm this is still an issue. I have tried with both npm -g postcss-cli
and a local installation.
Please share your hugo version
output.
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.
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.
A minimal demo repo is always helpful.
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.
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: https://github.com/golang/go/issues/15566 https://github.com/golang/go/issues/17149
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.
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.
I can build and test a branch locally if you need a Windows environment!
This came up again yesterday: https://discourse.gohugo.io/t/failed-to-transform-path-not-found/37309
On Windows, reproduce with:
git clone --single-branch -b hugo-github-issue-7333 https://github.com/jmooring/hugo-testing "hugo github issue 7333"
cd "hugo github issue 7333"
npm install
hugo server
There's a workaround where you don't have to change the project path:
"postcss": {
"plugins": {
"autoprefixer": {}
}
}
This came up again yesterday: https://discourse.gohugo.io/t/postcss-error/39101
Came across this today also. Project root had a folder in its path with a space and PostCSS errored out.
Update: For unrelated reason, I setup WSL1 on Win10 with node and hugo 104.1 to build/serve/watch my project which is on the windows mount and has spaces in the folders of the path and PostCSS works fine in this case.
I'm still having this issue as of 5/28/2020. I've narrowed down the issue to here: https://github.com/gohugoio/hugo/blob/6add6d77b48cf0aab8b39d7a2bddedb1aa2a52b8/resources/resource_transformers/postcss/postcss.go#L192
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:
This was closed as stale in #6283, but I think my solution should fix the problem.