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

auth-astro causes build to fail when building for cloudflare #43

Open
its-jman opened this issue Dec 20, 2023 · 2 comments
Open

auth-astro causes build to fail when building for cloudflare #43

its-jman opened this issue Dec 20, 2023 · 2 comments

Comments

@its-jman
Copy link

Repro:
https://github.com/its-jman/auth-astro-repro

When running astro build with auth() included as an integration, the build fails saying The package "path" wasn't found on the file system....

There seems to be a import "path"; injected at the beginning of the build output which causes this error

If you have ideas I'm happy to investigate further, but I haven't found any solutions so far.

astro.config.mjs:

import { defineConfig } from 'astro/config';
import cloudflare from "@astrojs/cloudflare";
import auth from "auth-astro";

export default defineConfig({
  integrations: [auth()],
  output: "server",
  adapter: cloudflare()
});
@its-jman
Copy link
Author

its-jman commented Dec 20, 2023

I've narrowed it down: injectEndpoints: false no longer errors, which makes sense since that code calls path.dirname and path.join, although that code is not included in the built file.

This is the first few lines of the built file that seems to be causing issues.
./dist/$server_build/chunks/pages/{hash}.mjs:

import 'path';
import { Auth } from '@auth/core';
import { splitCookiesString, parseString } from 'set-cookie-parser';
import { serialize } from 'cookie';
import Google from '@auth/core/providers/google';

const defineConfig = (config) => {
  config.prefix ??= "/api/auth";
  return config;
};

const authConfig = defineConfig({
  trustHost: true,
  secret: "1234",
  providers: [
    Google({
      clientId: "1234",
      clientSecret: "1234"
    })
  ]
});

@its-jman
Copy link
Author

Found a resolution by removing the path import in [...auth].ts and replacing it with a package import as recommended here. I did it using my packages name, but I'll create a draft pr to show the diff at least

https://github.com/its-jman/auth-astro

@its-jman its-jman mentioned this issue Dec 20, 2023
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

1 participant