auth-astro icon indicating copy to clipboard operation
auth-astro copied to clipboard

"astro add auth-astro" result in Cannot find module '\C:\projects\test\node_modules\auth-astro\src\api\[...auth].ts'

Open mdeloughry opened this issue 2 years ago • 6 comments

Using astro add auth-astro to add the auth to my project on Windows using the recommended process and base settings straight out of the box, then I get the following error.

npm run dev

> [email protected] dev
> astro dev

 error   Cannot find module '\C:\projects\test\node_modules\auth-astro\src\api\[...auth].ts'
  Require stack:
  - C:\projects\test\node_modules\astro\dist\core\routing\manifest\create.js
Error: Cannot find module '\C:\projects\test\node_modules\auth-astro\src\api\[...auth].ts'
Require stack:
- C:\projects\test\node_modules\astro\dist\core\routing\manifest\create.js
    at Module._resolveFilename (node:internal/modules/cjs/loader:1075:15)
    at Function.resolve (node:internal/modules/cjs/helpers:116:19)
    at injectedRouteToItem (file:///C:/projects/test/node_modules/astro/dist/core/routing/manifest/create.js:123:29)
    at file:///C:/projects/test/node_modules/astro/dist/core/routing/manifest/create.js:272:18
    at Array.sort (<anonymous>)
    at createRouteManifest (file:///C:/projects/test/node_modules/astro/dist/core/routing/manifest/create.js:269:56)
    at configureServer (file:///C:/projects/test/node_modules/astro/dist/vite-plugin-astro-server/plugin.js:18:22)
    at _createServer (file:///C:/projects/test/node_modules/vite/dist/node/chunks/dep-e8f070e8.js:63461:30)
    at async createContainer (file:///C:/projects/test/node_modules/astro/dist/core/dev/container.js:49:22)

I presume it's the initial \ as if I follow the path it does exist.

I've tried to do some digging to figure out the root cause but I have been unable to get to figure it out.

My Package.json

{
	"name": "astro-cactus",
	"version": "2.0.2",
	"private": false,
	"type": "module",
	"scripts": {
		"setup": "npx vite-node --config setup.vite.config.js setup.ts",
		"dev": "astro dev",
		"start": "astro dev",
		"sync": "astro sync",
		"build": "prisma generate && astro build",
		"preview": "astro preview",
		"format": "prettier -w ./src ./src/**/*.astro"
	},
	"devDependencies": {
		"@astrojs/image": "0.13.0",
		"@astrojs/mdx": "^0.15.1",
		"@astrojs/sitemap": "^1.0.0",
		"@astrojs/tailwind": "3.0.0",
		"@import-meta-env/unplugin": "^0.4.7",
		"@tailwindcss/aspect-ratio": "^0.4.2",
		"@tailwindcss/line-clamp": "^0.4.2",
		"@tailwindcss/typography": "^0.5.8",
		"@types/eslint": "^8.4.10",
		"@types/prettier": "^2.7.2",
		"@types/sharp": "^0.31.1",
		"@typescript-eslint/eslint-plugin": "^5.48.0",
		"@typescript-eslint/parser": "^5.48.0",
		"astro-eslint-parser": "^0.11.0",
		"autoprefixer": "^10.4.13",
		"eslint": "^8.32.0",
		"eslint-config-prettier": "^8.6.0",
		"eslint-import-resolver-typescript": "^3.5.2",
		"eslint-plugin-astro": "^0.23.0",
		"eslint-plugin-import": "^2.26.0",
		"eslint-plugin-jsx-a11y": "^6.7.1",
		"eslint-plugin-prettier": "^4.2.1",
		"nodemailer": "^6.9.3",
		"postcss": "^8.4.21",
		"postcss-html": "^1.5.0",
		"prettier": "^2.8.3",
		"prettier-plugin-astro": "0.8.0",
		"prettier-plugin-tailwindcss": "^0.2.2",
		"stylelint": "^14.16.1",
		"stylelint-config-prettier": "^9.0.4",
		"stylelint-config-standard": "^29.0.0",
		"tailwindcss": "^3.2.4",
		"typescript": "^4.9.4"
	},
	"dependencies": {
		"@astrojs/netlify": "^2.1.2",
		"@astrojs/prefetch": "^0.1.1",
		"@astrojs/react": "^2.0.2",
		"@astrojs/rss": "^2.0.0",
		"@auth/core": "^0.5.1",
		"@netlify/planetscale": "^1.0.0",
		"@planetscale/database": "^1.6.0",
		"@prisma/client": "^4.15.0",
		"@resvg/resvg-js": "^2.4.1",
		"@types/jsonwebtoken": "^9.0.2",
		"@types/react": "^18.0.27",
		"@types/react-dom": "^18.0.10",
		"@types/spotify-api": "^0.0.20",
		"astro": "^2.6.3",
		"auth-astro": "^3.0.1",
		"dotenv": "^16.0.3",
		"emoji-unicode-map": "^1.1.11",
		"jsdom": "^22.0.0",
		"jsonwebtoken": "^9.0.0",
		"node-fetch": "^3.3.1",
		"prisma": "^4.15.0",
		"react": "^18.2.0",
		"react-dom": "^18.2.0",
		"reflect-metadata": "^0.1.13",
		"satori": "0.1.2",
		"satori-html": "^0.3.2",
		"sharp": "^0.31.3",
		"swr": "^2.0.3"
	}
}

Please let me know any other information you'd require and I'll get them to you asap

mdeloughry avatar Jun 11 '23 17:06 mdeloughry

Hi, could you also provide the your Astro config please? If you have the auth config in a seperate file please also send this :)

nowaythatworked avatar Jun 11 '23 17:06 nowaythatworked

Sure thing here's the astro config

import { defineConfig } from "astro/config";
import mdx from "@astrojs/mdx";
import tailwind from "@astrojs/tailwind";
import image from "@astrojs/image";
import sitemap from "@astrojs/sitemap";
import prefetch from "@astrojs/prefetch";

import react from "@astrojs/react";

// https://astro.build/config
import netlify from "@astrojs/netlify/functions";

// https://astro.build/config;
import auth from "auth-astro"

// https://astro.build/config
export default defineConfig({
  site: "https://deloughry.co.uk",
  markdown: {
    shikiConfig: {
      theme: "poimandres",
      wrap: false
    }
  },
  output: "server",
  integrations: [mdx({}), tailwind({
    config: {
      applyBaseStyles: false
    }
  }), image({
    serviceEntryPoint: "@astrojs/image/sharp"
  }),
  sitemap(),
  prefetch(),
  react(),
  auth(),
  ],
  vite: {
    optimizeDeps: {
      exclude: ["@resvg/resvg-js"]
    }
  },
  adapter: netlify()
});

and here's the auth config

import CredentialsProvider from '@auth/core/providers/credentials'

export default {
  providers: [
    CredentialsProvider({
      async authorize(credentials) {
        const authResponse = await fetch("/api/protected/auth", {
          method: "POST",
          headers: {
            "Content-Type": "application/json",
          },
          body: JSON.stringify(credentials),
        })

        if (!authResponse.ok) {
          return null
        }

        const user = await authResponse.json()

        return user
      },
    }),
  ],
}

mdeloughry avatar Jun 11 '23 17:06 mdeloughry

Is your config named 'auth.config.ts' or something else? If it's something else you need to define the path in the auth. Integration with the parameter 'configFile'

nowaythatworked avatar Jun 11 '23 18:06 nowaythatworked

That was it!

Oh my I'm sorry! 😅 But thank you so much for the help, I had misread the readme! and named it [...auth].ts

If it's okay with yourself I may tweak the ReadMe a little bit and submit a PR just to clear the process up a little.

mdeloughry avatar Jun 11 '23 18:06 mdeloughry

I'm glad I could help 😄 Yes please do so, I highly appreciate the community feedback :)

nowaythatworked avatar Jun 11 '23 18:06 nowaythatworked

Sorry, I think I was too eager to close this.

After closing, I decided to test the authentication since I assumed it was working fine as I could launch the server. However, I encountered some issues when trying to get the login components to work. I kept getting a 404 error on the CSRF call.

Thinking that I might have made a mistake during the setup, I started fresh and followed the tutorial from otterlord . But I ended up encountering the same error mentioned at the beginning of the ticket. I suppose I must have confused the system, which is why the error was hidden initially.

The strange thing is that when I boot the project in something like Codespaces or GitPod and run it, it works fine. Even more peculiar, when I checked out TheOtterlord's astro-auth-example on my Windows machine, it also worked. So, I'm not sure if it's something to do with the combination of versions/packages I have or if there's another factor at play.

When I have some free time, I'll try starting a fresh project, but for now, I would like to reopen the ticket.

mdeloughry avatar Jun 12 '23 20:06 mdeloughry