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

Empty robots.txt file created when building on Windows #4

Closed
sebthom opened this issue Dec 13, 2024 · 0 comments
Closed

Empty robots.txt file created when building on Windows #4

sebthom opened this issue Dec 13, 2024 · 0 comments

Comments

@sebthom
Copy link

sebthom commented Dec 13, 2024

Running pnpm build creates an empty robots.txt file on Windows and logs this error:

Error reading file size: Error: ENOENT: no such file or directory, stat 'D:\D:\projects\website\dist\robots.txt'
    at async Object.stat (node:internal/fs/promises:1032:18)
    at async getFileSizeInKilobytes (file:///D:/projects/website/node_modules/.pnpm/astro-robots@2.3.0_astro@4.16.17_@types+node@22.10.2_lightningcss@1.27.0_rollup@4.28.1_sass-e_tp2hgc74ezatvlr2qm3gadxkx4/node_modules/astro-robots/dist/index.mjs:154:21)
    at async astro:build:done (file:///D:/projects/website/node_modules/.pnpm/astro-robots@2.3.0_astro@4.16.17_@types+node@22.10.2_lightningcss@1.27.0_rollup@4.28.1_sass-e_tp2hgc74ezatvlr2qm3gadxkx4/node_modules/astro-robots/dist/index.mjs:228:26)
    at async withTakingALongTimeMsg (file:///D:/projects/website/node_modules/.pnpm/astro@4.16.17_@types+node@22.10.2_lightningcss@1.27.0_rollup@4.28.1_sass-embedded@1.81.0_sass_4ofjof7rilz4bhwqyz7ldguqge/node_modules/astro/dist/integrations/hooks.js:25:18)
    at async runHookBuildDone (file:///D:/projects/website/node_modules/.pnpm/astro@4.16.17_@types+node@22.10.2_lightningcss@1.27.0_rollup@4.28.1_sass-embedded@1.81.0_sass_4ofjof7rilz4bhwqyz7ldguqge/node_modules/astro/dist/integrations/hooks.js:428:7)
    at async AstroBuilder.build (file:///D:/projects/website/node_modules/.pnpm/astro@4.16.17_@types+node@22.10.2_lightningcss@1.27.0_rollup@4.28.1_sass-embedded@1.81.0_sass_4ofjof7rilz4bhwqyz7ldguqge/node_modules/astro/dist/core/build/index.js:159:5)
    at async AstroBuilder.run (file:///D:/projects/website/node_modules/.pnpm/astro@4.16.17_@types+node@22.10.2_lightningcss@1.27.0_rollup@4.28.1_sass-embedded@1.81.0_sass_4ofjof7rilz4bhwqyz7ldguqge/node_modules/astro/dist/core/build/index.js:182:7)
    at async build (file:///D:/projects/website/node_modules/.pnpm/astro@4.16.17_@types+node@22.10.2_lightningcss@1.27.0_rollup@4.28.1_sass-embedded@1.81.0_sass_4ofjof7rilz4bhwqyz7ldguqge/node_modules/astro/dist/core/build/index.js:51:3)
    at async build (file:///D:/projects/website/node_modules/.pnpm/astro@4.16.17_@types+node@22.10.2_lightningcss@1.27.0_rollup@4.28.1_sass-embedded@1.81.0_sass_4ofjof7rilz4bhwqyz7ldguqge/node_modules/astro/dist/cli/build/index.js:24:3)
    at async runCommand (file:///D:/projects/website/node_modules/.pnpm/astro@4.16.17_@types+node@22.10.2_lightningcss@1.27.0_rollup@4.28.1_sass-embedded@1.81.0_sass_4ofjof7rilz4bhwqyz7ldguqge/node_modules/astro/dist/cli/index.js:147:7) {
  errno: -4058,
  code: 'ENOENT',
  syscall: 'stat',
  path: 'D:\\D:\\projects\\website\\dist\\robots.txt'
}
18:41:47 [astro-robots] `robots.txt` (0KB) created at `dist` in 0ms

D:\\D:\\ looks wrong.

I am using a config like this:

    robots({
      sitemap: [
        "https://example.com/sitemap-index.xml"
      ],
      policy: [
        {
          userAgent: "*",
          disallow: ["/"],
        },
        {
          userAgent: [
            "Applebot",
            "bingbot",
            "DuckDuckBot",
            "Googlebot",
            "Qwantify",
          ],
          allow: ["/"],
          disallow: [
            "/login",
            "/admin",
          ],
          crawlDelay: 5,
        },
      ]
    })

I saw you are using this in the code const filePath = fileUrl.pathname; I think this is an unsafe conversion and you should use:

import { fileURLToPath } from "url";
const filePath = fileURLToPath(fileUrl);
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

2 participants