eleventy-vite-plugin and the Output Directory
I added the Eleventy Vite plugin to a project this week to get some JavaScript (technically, TypeScript) working with minimum fuss. The overall experience is good, but not entirely without issues. First, I encountered a known bug on my Windows machine:
[11ty] Problem writing Eleventy templates: (more in DEBUG output) [11ty] EPERM: operation not permitted, rename 'C:\path\to\redacted\dist' -> 'C:\path\to\redacted\.11ty-vite' (via Error) [11ty] [11ty] Original error stack trace: Error: EPERM: operation not permitted, rename 'C:\path\to\redacted\dist' -> 'C:\path\to\redacted\.11ty-vite'
Fortunately, this doesn’t seem to prevent the bundle from working, so I ignored it. When I deployed the revised version to Netlify, however, I was rather confused by a different plugin error:
11:38:18 PM: [11ty] Encountered a Vite build error, restoring original Eleventy output to dist Error: Unexpected output path (was not in output directory dist): ./dist/en/index.html 11:38:18 PM: at /opt/build/repo/node_modules/.pnpm/@11ty+eleventy-plugin-vite@4.0.0_sass@1.77.8/node_modules/@11ty/eleventy-plugin-vite/EleventyVite.js:63:19 11:38:18 PM: at Array.map (<anonymous>) 11:38:18 PM: at EleventyVite.runBuild (/opt/build/repo/node_modules/.pnpm/@11ty+eleventy-plugin-vite@4.0.0_sass@1.77.8/node_modules/@11ty/eleventy-plugin-vite/EleventyVite.js:61:10) 11:38:18 PM: at async AsyncEventEmitter.<anonymous> (/opt/build/repo/node_modules/.pnpm/@11ty+eleventy-plugin-vite@4.0.0_sass@1.77.8/node_modules/@11ty/eleventy-plugin-vite/.eleventy.js:55:5) 11:38:18 PM: at async Promise.all (index 0) 11:38:18 PM: at async Eleventy.executeBuild (file:///opt/build/repo/node_modules/.pnpm/@11ty+eleventy@3.0.0-alpha.10/node_modules/@11ty/eleventy/src/Eleventy.js:1289:4) 11:38:18 PM: [11ty] Problem writing Eleventy templates: (more in DEBUG output) 11:38:18 PM: [11ty] ENOENT: no such file or directory, lstat '/opt/build/repo/.11ty-vite' (via Error) 11:38:18 PM: [11ty] 11:38:18 PM: [11ty] Original error stack trace: Error: ENOENT: no such file or directory, lstat '/opt/build/repo/.11ty-vite' 11:38:18 PM: [11ty] Copied 11 files / Wrote 44 files in 2.96 seconds (67.3ms each, v3.0.0-alpha.10)
The key is the line about the unexpected output path (namely,
./dist/en/index.html not being inside dist).
Now, I don’t know what should happen here, but, after looking
at
the plugin’s source code, I changed the Eleventy output directory from dist to
./dist as a workaround.
Et voilà ! Everything worked.