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

TS2305: Module "astro:actions" has no exported member actions #11893

Closed
1 task
alfi-dim opened this issue Aug 31, 2024 · 3 comments
Closed
1 task

TS2305: Module "astro:actions" has no exported member actions #11893

alfi-dim opened this issue Aug 31, 2024 · 3 comments
Labels
needs repro Issue needs a reproduction

Comments

@alfi-dim
Copy link

alfi-dim commented Aug 31, 2024

Astro Info

Astro                    v4.15.1
Node                     v18.20.4
System                   Windows (x64)
Package Manager          unknown
Output                   hybrid
Adapter                  none
Integrations             @astrojs/tailwind
                         @astrojs/preact

If this issue only occurs in one browser, which browser is a problem?

No response

Describe the Bug

Got TS2305: Module "astro:actions" has no exported member actions when import { actions } from 'astro:actions';

full code:
my actions/index.ts

import { defineAction, ActionError } from 'astro:actions';
import { z } from "astro:content";

import {app} from '../firebase/server.ts';
import { getFirestore } from 'firebase-admin/firestore';

export const server = {
  getData: defineAction({
    input: z.object({
      docName: z.string().min(1),
    }),
    handler: async (input: { docName: string }) => {
      try {
        const db = getFirestore(app);
        const doc = await db.collection('test').doc(input.docName).get();
        console.log('doc.data()', doc.data());
        return doc.data();
      } catch (error) {
        return new ActionError({
          code: 'INTERNAL_SERVER_ERROR',
          message: `An error occurred while fetching data: ${error.message}`,
        });
      }
    }
  })
};

my preact component

import { actions } from 'astro:actions';
import {useEffect, useState} from "preact/hooks";

export default function TestFirebase() {
  const [data, setData] = useState([]);

  useEffect(() => {
    const f = async () => {
      const d = await actions.getData({docName: 'test'})
      setData(d)
    }
    f()
  }, [])
  return (
    <div>
      <h1>TestFirebase</h1>
      <ul>
        {
          data.map((d) => <li>d</li>)
        }
      </ul>
    </div>
  );
}

index.astro

import { defineAction, ActionError } from 'astro:actions';
import { z } from "astro:content";

import {app} from '../firebase/server.ts';
import { getFirestore } from 'firebase-admin/firestore';

export const server = {
  getData: defineAction({
    input: z.object({
      docName: z.string().min(1),
    }),
    handler: async (input: { docName: string }) => {
      try {
        const db = getFirestore(app);
        const doc = await db.collection('test').doc(input.docName).get();
        console.log('doc.data()', doc.data());
        return doc.data();
      } catch (error) {
        return new ActionError({
          code: 'INTERNAL_SERVER_ERROR',
          message: `An error occurred while fetching data: ${error.message}`,
        });
      }
    }
  })
};

What's the expected result?

it should import actions correctly

Link to Minimal Reproducible Example

Participation

  • I am willing to submit a pull request for this issue.
@github-actions github-actions bot added the needs triage Issue needs to be triaged label Aug 31, 2024
@florian-lefebvre florian-lefebvre added needs repro Issue needs a reproduction and removed needs triage Issue needs to be triaged labels Sep 1, 2024
Copy link
Contributor

github-actions bot commented Sep 1, 2024

Hello @alfi-dim. Please provide a minimal reproduction using a GitHub repository or StackBlitz. Issues marked with needs repro will be closed if they have no activity within 3 days.

@aretrace
Copy link

aretrace commented Sep 3, 2024

@alfi-dim did you run the dev server?
apparently it's code generated

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Sep 6, 2024
@groteck
Copy link

groteck commented Sep 6, 2024

I found the same issue, migrating from:

  • astro 4.11.5
  • astro 4.15.3
    The error happens only on build time

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs repro Issue needs a reproduction
Projects
None yet
Development

No branches or pull requests

4 participants