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

Getting ReferenceError: process is not defined when attempting to import Schema into Astro React component #13729

Closed
nadetastic opened this issue Aug 13, 2024 · 7 comments
Assignees
Labels
bug Something isn't working Core Related to core Amplify issues

Comments

@nadetastic
Copy link
Member

nadetastic commented Aug 13, 2024

Environment information

System:
  OS: macOS 14.4.1
  CPU: (12) x64 Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz
  Memory: 75.01 MB / 16.00 GB
  Shell: /bin/zsh
Binaries:
  Node: 18.18.2 - ~/.nvm/versions/node/v18.18.2/bin/node
  Yarn: undefined - undefined
  npm: 10.2.1 - ~/.nvm/versions/node/v18.18.2/bin/npm
  pnpm: 8.12.1 - /usr/local/bin/pnpm
NPM Packages:
  @aws-amplify/auth-construct: 1.2.0
  @aws-amplify/backend: 1.0.4
  @aws-amplify/backend-auth: 1.1.1
  @aws-amplify/backend-cli: 1.2.2
  @aws-amplify/backend-data: 1.1.0
  @aws-amplify/backend-deployer: 1.0.3
  @aws-amplify/backend-function: 1.3.0
  @aws-amplify/backend-output-schemas: 1.1.0
  @aws-amplify/backend-output-storage: 1.0.2
  @aws-amplify/backend-secret: 1.0.0
  @aws-amplify/backend-storage: 1.0.4
  @aws-amplify/cli-core: 1.1.1
  @aws-amplify/client-config: 1.1.2
  @aws-amplify/deployed-backend-client: 1.2.0
  @aws-amplify/form-generator: 1.0.0
  @aws-amplify/model-generator: 1.0.3
  @aws-amplify/platform-core: 1.0.4
  @aws-amplify/plugin-types: 1.1.0
  @aws-amplify/sandbox: 1.1.1
  @aws-amplify/schema-generator: 1.2.0
  aws-amplify: 6.5.0
  aws-cdk: 2.151.0
  aws-cdk-lib: 2.151.0
  typescript: 5.5.4
AWS environment variables:
  AWS_STS_REGIONAL_ENDPOINTS = regional
  AWS_NODEJS_CONNECTION_REUSE_ENABLED = 1
  AWS_SDK_LOAD_CONFIG = 1
No CDK environment variables

Description

I'm trying out Astro with Amplify Gen2 and came across an error when attempting to import the Schema from defineData into a React component in Astro

Here are my components

todo/[...slug].astro

---
import { amplifyDataClient } from "@/components/react/ConfigureAmplifyClientSide";
import { TodoCard } from "@/components/react/TodoCard";
import type { Schema } from "amplify/data/resource"; // <-- this doesn't throw an error

export async function getStaticPaths() {
  const { data } = await amplifyDataClient.models.Todo.list();
  return data.map((todo) => ({
    params: { slug: todo.id },
    props: todo,
  }));
}

type Props = Schema["Todo"]["type"];
const todo = Astro.props;
---

<TodoCard todo={todo} client:load />

TodoCard.tsx

import { type Schema } from "amplify/data/resource"; // <-- This throws an error by simply importing it
type Todo = Schema["Todo"]["type"];

export const TodoCard = ({ todo }: { todo: Todo }) => {

  return JSON.stringify(todo);
}

With this I get the following error in the browser console

Screenshot 2024-08-13 at 2 51 14 PM
@nadetastic nadetastic added the pending-triage Issue is pending triage label Aug 13, 2024
@nadetastic
Copy link
Member Author

Just solved this I think, the issue seems to be the syntax

import { type Schema } from "amplify/data/resource"; // <-- Throws an error
import type { Schema } from "amplify/data/resource"; // <-- Works 

Not sure if its something specific to astro, as I haven't had this issue before and Im relatively new to astro

@ykethan
Copy link
Member

ykethan commented Aug 13, 2024

Hey,👋 thanks for raising this! I'm going to transfer this over to our API repository for better assistance 🙂

@ykethan ykethan transferred this issue from aws-amplify/amplify-backend Aug 13, 2024
@ykethan ykethan added the Gen 2 Issues related to Gen 2 Amplify projects label Aug 13, 2024
@nadetastic
Copy link
Member Author

Adding tsconfig

{
  "extends": "astro/tsconfigs/strict",
  "compilerOptions": {
    "jsx": "react-jsx",
    "jsxImportSource": "react",
    "baseUrl": ".",
    "paths": {
      "@/*": [
        "./src/*"
      ]
    }
  }
}

@josefaidt
Copy link
Contributor

Import declarations written with import type, export declarations written with export type { ... }, and import or export specifiers prefixed with the type keyword are all guaranteed to be elided from the output JavaScript.
https://www.typescriptlang.org/docs/handbook/modules/reference.html#type-only-imports-and-exports

While I'm not able to reproduce this in a .astro file I have not yet attempted to import in a React component, therefore this may be due to how those components are transpiled and passed to the bundler.

That being said this should be removed when verbatimModuleSyntax is set to true, as specified by Astro's base tsconfig

@nadetastic does this occur with import { type... in Astro components themselves?

@nadetastic
Copy link
Member Author

@josefaidt Nope that doesn't throw an error - seems specific to react components, haven't tried Vue/others

@chrisbonifacio chrisbonifacio self-assigned this Aug 19, 2024
@chrisbonifacio chrisbonifacio added bug Something isn't working and removed pending-triage Issue is pending triage labels Aug 19, 2024
@chrisbonifacio
Copy link
Member

chrisbonifacio commented Aug 19, 2024

Going to mark this as a bug for now since it's consistently reproducible. I couldn't find any existing bugs in the Astro repo or elsewhere. Seems unique to react components in Astro at the moment.

But, while it's a runtime issue, it doesn't seem to be related to data-schema. So, i'm going to transfer this to the JS repo.

@chrisbonifacio chrisbonifacio transferred this issue from aws-amplify/amplify-category-api Aug 19, 2024
@cwomack cwomack assigned cwomack and unassigned chrisbonifacio Oct 17, 2024
@cwomack cwomack added Core Related to core Amplify issues and removed Gen 2 Issues related to Gen 2 Amplify projects labels Oct 17, 2024
@cwomack
Copy link
Member

cwomack commented Oct 24, 2024

Closing this issue as it's not Amplify related, but rather on the Astro side of things. We'll monitor Astro repo for a related bug and cross link.

@cwomack cwomack closed this as not planned Won't fix, can't repro, duplicate, stale Oct 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Core Related to core Amplify issues
Projects
None yet
Development

No branches or pull requests

5 participants