I switched to using "import * as " and encountered error: Entity is not defined

55 Views Asked by At

I used "import * as Article" instead of "import { Article }," and then an error occurred when I ran "yarn dev". The error is:

jiahao@jiahaodeMacBook-Air-2 graphql-sst-sample % yarn dev
yarn run v1.22.19
$ npm run env:local sst dev

> [email protected] env:local
> env-cmd -f .env.local -- sst dev

SST v2.16.3  ready!

➜  App:     graphql-sst-sample
   Stage:   develop
   Console: https://console.sst.dev/graphql-sst-sample/develop

✖  Pothos: Failed to extract schema:
   Entity is not defined

✔  Deployed:
   Database
   Api
   API: https://hogt05y159.execute-api.ap-northeast-1.amazonaws.com
   Web

Here is the code change of my repo:

-import { Article } from "../../../../core/src/article";
+import * as Article from "../../../../core/src/article";

The PR of my repo: https://github.com/kody-liou/graphql-sst-sample/pull/4

The steps to reproduce error:

Prerequest

  1. Install nvm:

Follow the instructions at https://github.com/nvm-sh/nvm to install nvm.

  1. Install Node.js 18: Run the following command to install Node.js 18 using nvm:
nvm install 18
  1. Install Yarn: Run the following command to install Yarn globally:
npm i -g yarn
  1. Create an AWS account

  2. Create a .env.local file in the project's root folder with the following content:

AWS_ACCESS_KEY_ID=your access key id
AWS_SECRET_ACCESS_KEY=your secret access key
# Region ap-northeast-1 is at tokyo
AWS_REGION=ap-northeast-1
NODE_ENV=development

Getting Started

  1. Open the JavaScript Debug Terminal and execute the following command:
yarn dev
  1. Open another terminal and execute the following command:
yarn dev:web

I expect after I run "yarn dev", the error message:

✖  Pothos: Failed to extract schema:
   Entity is not defined

will disappear.

0

There are 0 best solutions below