Fixing Line Endings
Unfinished article
So I had some problems with initializing this site during the Netlify build process. The logs suggested I only needed to add an extra \ to my \s in the netlify.toml file. However the problem was to do with the difference between the way Linux and Windows create line endings. Windows uses CRLF while Linux uses LF.
To fix the immediate problem from Linux I used the dos2unix CLI app. Very easy to do: dos2unix netlify.toml.
For a more permanent fix to the issue which arises from switching between editing the site on both Windows and Linux I created a .gitattributes file in the root of the project with one line.
1# enforce LF for Netlify config
2netlify.toml text eol=lf
Not had time yet to test the efficacy of this yet as I don’t use Windows at the moment. However I will be adding a .gitattributes file to other netlify projects.
More
Not tried the following yet but worth noting:
Another recommendation was..
Replace the multi-line/backslash-style build.command with a single-line command to avoid escaping/newline issues. Edit netlify.toml so the build section looks like:
1[build]
2 command = "git config core.quotepath false && hugo --gc --minify --baseURL \"${URL}\""
3 publish = "public"
Also recommended is:
Double-check Netlify environment variables
Verify no trailing CR or whitespace was accidentally copied into any environment variable (especially URL) in the Netlify UI (Site settings → Build & deploy → Environment variables / Build & deploy settings).
Full AI generated explanation
The Netlify deploy errored, with the following guidance provided:
Relevant log lines
- line 69: bash: line 1: $’\r’: command not found
- line 72: ERROR failed to create config from result: parse “https://blank-try.netlify.app\r”: net/url: invalid control character in URL
- lines 94-99: resolved build.command contains embedded “\r” sequences
Diagnosis
- Error type: build script failure caused by Windows-style CRLF carriage returns (\r) embedded in the Netlify build command / config. The CR (\r) is being passed into the shell and into the URL substitution (${URL}), causing bash to see
$'\r'and Hugo/Go to see an invalid control character in the baseURL. - Root cause: netlify.toml (or whatever configuration/command string you provided) contains CRLF line endings and/or literal \r characters (likely from authoring on Windows or copy-pasting). Netlify reads that into the resolved config (see the “\r” shown in lines 94-99), which produces the errors in line 69 and line 72.
Solution
Verify
netlify.tomlis present and committed- Ensure
netlify.toml(or the file where you set build.command) is in the repo and committed before changing line endings.
- Ensure
Remove CRLFs and make build.command a plain Unix-style line
- On macOS / Linux (run in repo root):
1# remove CR characters from netlify.toml 2sed -i 's/\r$//' netlify.toml 3git add netlify.toml 4git commit -m "Fix CRLF -> LF in netlify.toml" 5git push - Or use dos2unix:
1dos2unix netlify.toml 2git add netlify.toml && git commit -m "Convert netlify.toml to LF" && git push - On Windows: open netlify.toml in your editor (VS Code) and set End of Line sequence to LF, save, commit and push.
- On macOS / Linux (run in repo root):
(Recommended) Replace the multi-line/backslash-style build.command with a single-line command to avoid escaping/newline issues. Edit netlify.toml so the build section looks like:
1[build] 2 command = "git config core.quotepath false && hugo --gc --minify --baseURL \"${URL}\"" 3 publish = "public"- Commit and push after editing.
Prevent regressions
- Add a .gitattributes entry to force LF for the file:Commit and push .gitattributes.
1# enforce LF for Netlify config 2netlify.toml text eol=lf
- Add a .gitattributes entry to force LF for the file:
Double-check Netlify environment variables
- Verify no trailing CR or whitespace was accidentally copied into any environment variable (especially URL) in the Netlify UI (Site settings → Build & deploy → Environment variables / Build & deploy settings).
Redeploy
If you want, paste the current contents of netlify.toml here and I can show the exact edits to make.
The relevant error logs are:
1Line 0: build-image version: ac6eb13fbf000e5c09ad677efd8b7c3c2d0142b6 (noble-new-builds)
2Line 1: buildbot version: 24ab26d65f817590ea807b86ec0d98d4dcebe8f9
3Line 2: Fetching cached dependencies
4Line 3: Failed to fetch cache, continuing with build
5Line 4: Starting to prepare the repo for build
6Line 5: No cached dependencies found. Cloning fresh repo
7Line 6: git clone --filter=blob:none git@gitlab.com:xixianykus/blank-try
8Line 7: Preparing Git Reference refs/heads/master
9Line 8: Custom build command detected. Proceeding with the specified command: '\
10 git config core.quotepath false && \
11 hugo --gc --
12Line 9: Installing dependencies
13Line 10: mise ~/.config/mise/config.toml tools: python@3.14.3
14Line 11: mise ~/.config/mise/config.toml tools: ruby@3.4.8
15Line 12: mise go@1.26.3 [1/3] install
16Line 13: mise go@1.26.3 [1/3] download go1.26.3.linux-amd64.tar.gz
17Line 62: $ \
18Line 63:
19Line 64: git config core.quotepath false && \
20Line 65:
21Line 66: hugo --gc --minify --baseURL "${URL}"
22Line 67:
23Line 68:
24Line 69: bash: line 1: $'\r': command not found
25Line 70: bash: line 2: $'\r': command not found
26Line 71: Total in 1 ms
27Line 72: ERROR failed to create config from result: parse "https://blank-try.netlify.app\r": net/url: invalid control character in URL
28Line 73:
29Line 74: "build.command" failed
30Line 75: ────────────────────────────────────────────────────────────────
31Line 76:
32Line 77: Error message
33Line 78: Command failed with exit code 1: \" version.build_image_name=noble-new-builds version.buildbot=24ab26d65f817590ea807b86ec0d98d
34Line 79:
35Line 80: git config core.quotepath false && \" netlify_git_mode=zip_only firebase_url=
36Line 81:
37Line 82: hugo --gc --minify --baseURL "${URL}"
38Line 83:
39Line 84: Error location
40Line 85: In build.command from netlify.toml:
41Line 86: \" repo_url=
42Line 87:
43Line 88: git config core.quotepath false && \" worker_id=24 repo_url=
44Line 89:
45Line 90: hugo --gc --minify --baseURL "${URL}"
46Line 91:
47Line 92: Resolved config
48Line 93: build:
49Line 94: command: "\\\r
50
51Line 95: \ git config core.quotepath false && \\\r
52Line 96:
53Line 97: \ hugo --gc --minify --baseURL \"${URL}\"\r
54
55Line 98: environment:
56Line 99: \ "
57 commandOrigin: config
58Line 100: - HUGO_VERSION
59Line 101: - NODE_VERSION
60Line 102: - TZ
61Line 103: publish: /opt/build/repo/public
62Line 104: publishOrigin: config
63Line 105: Failed during stage 'building site': Build script returned non-zero exit code: 2
64Line 106: Build failed due to a user error: Build script returned non-zero exit code: 2
65Line 107: Failing build: Failed to build site
66Line 108: Finished processing build request in 15.447s