aws-amplify / amplify-category-api

The AWS Amplify CLI is a toolchain for simplifying serverless web and mobile development. This plugin provides functionality for the API category, allowing for the creation and management of GraphQL and REST based backends for your amplify project.
https://docs.amplify.aws/
Apache License 2.0
89 stars 77 forks source link

TypeScript error TS1205 when using @aws-amplify/graphql-transformer-interfaces with --isolatedModules #807

Open acusti opened 2 years ago

acusti commented 2 years ago

Before opening, please confirm:

How did you install the Amplify CLI?

yarn

If applicable, what version of Node.js are you using?

v18.7.0

Amplify CLI Version

10.0.0

What operating system are you using?

macOS 12.1

Did you make any manual changes to the cloud resources managed by Amplify? Please describe the changes made.

No manual changes made

Amplify Categories

auth, custom, storage, function, api

Amplify Commands

push

Describe the bug

I have a custom resource that depends on @aws-amplify/cli-extensibility-helper. when i upgraded that dependency from 2.3.262.3.34, i started getting an error when executing amplify push (i’m using yarn workspaces, hence why the paths are prefixed with ../../../../../):

🛑 There was an error building the custom resources
🛑 Error: Command failed with exit code 2: /Users/…/amplify/backend/custom/VideoOnDemand/node_modules/.bin/tsc
../../../../../node_modules/@aws-amplify/graphql-transformer-interfaces/src/index.ts(2,10): error TS1205: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'.
… [see “Log output” for complete logs]

i worked around the issue by adding "isolatedModules": false to the compilerOptions in my tsconfig.json for that custom resource. the issue can be resolved by using type-only imports and exports. this will make is so that files like https://github.com/aws-amplify/amplify-category-api/blob/main/packages/amplify-graphql-transformer-interfaces/src/transformer-plugin-provider.ts, which only import and export types and have no actual code exports, can still be compiled as isolated modules.

Expected behavior

i expected the custom resource to build without error

Reproduction steps

  1. add a custom resource
  2. add latest @aws-amplify/cli-extensibility-helper (v2.3.34) as dependency
  3. use typescript@4.8.3 (other versions may reproduce, i haven’t checked)
  4. ensure tsconfig.json doesn’t overwrite isolatedModules
  5. run amplify push

GraphQL schema(s)

No response

Log output

``` # Put your logs below this line 🛑 There was an error building the custom resources 🛑 Error: Command failed with exit code 2: /Users/…/amplify/backend/custom/VideoOnDemand/node_modules/.bin/tsc ../../../../../node_modules/@aws-amplify/graphql-transformer-interfaces/src/index.ts(2,10): error TS1205: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'. ../../../../../node_modules/@aws-amplify/graphql-transformer-interfaces/src/index.ts(7,3): error TS1205: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'. ../../../../../node_modules/@aws-amplify/graphql-transformer-interfaces/src/index.ts(8,3): error TS1205: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'. ../../../../../node_modules/@aws-amplify/graphql-transformer-interfaces/src/index.ts(9,3): error TS1205: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'. ../../../../../node_modules/@aws-amplify/graphql-transformer-interfaces/src/index.ts(11,10): error TS1205: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'. ../../../../../node_modules/@aws-amplify/graphql-transformer-interfaces/src/index.ts(14,3): error TS1205: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'. ../../../../../node_modules/@aws-amplify/graphql-transformer-interfaces/src/index.ts(15,3): error TS1205: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'. ../../../../../node_modules/@aws-amplify/graphql-transformer-interfaces/src/index.ts(16,3): error TS1205: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'. ../../../../../node_modules/@aws-amplify/graphql-transformer-interfaces/src/index.ts(17,3): error TS1205: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'. ../../../../../node_modules/@aws-amplify/graphql-transformer-interfaces/src/index.ts(18,3): error TS1205: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'. ../../../../../node_modules/@aws-amplify/graphql-transformer-interfaces/src/index.ts(19,3): error TS1205: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'. ../../../../../node_modules/@aws-amplify/graphql-transformer-interfaces/src/index.ts(20,3): error TS1205: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'. ../../../../../node_modules/@aws-amplify/graphql-transformer-interfaces/src/index.ts(21,3): error TS1205: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'. ../../../../../node_modules/@aws-amplify/graphql-transformer-interfaces/src/index.ts(23,3): error TS1205: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'. ../../../../../node_modules/@aws-amplify/graphql-transformer-interfaces/src/index.ts(24,3): error TS1205: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'. ../../../../../node_modules/@aws-amplify/graphql-transformer-interfaces/src/index.ts(25,3): error TS1205: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'. ../../../../../node_modules/@aws-amplify/graphql-transformer-interfaces/src/index.ts(26,3): error TS1205: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'. ../../../../../node_modules/@aws-amplify/graphql-transformer-interfaces/src/index.ts(27,3): error TS1205: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'. ../../../../../node_modules/@aws-amplify/graphql-transformer-interfaces/src/index.ts(28,3): error TS1205: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'. ../../../../../node_modules/@aws-amplify/graphql-transformer-interfaces/src/index.ts(29,3): error TS1205: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'. ../../../../../node_modules/@aws-amplify/graphql-transformer-interfaces/src/index.ts(30,3): error TS1205: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'. ../../../../../node_modules/@aws-amplify/graphql-transformer-interfaces/src/index.ts(31,3): error TS1205: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'. ../../../../../node_modules/@aws-amplify/graphql-transformer-interfaces/src/index.ts(32,3): error TS1205: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'. ../../../../../node_modules/@aws-amplify/graphql-transformer-interfaces/src/index.ts(35,10): error TS1205: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'. ../../../../../node_modules/@aws-amplify/graphql-transformer-interfaces/src/index.ts(35,33): error TS1205: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'. ../../../../../node_modules/@aws-amplify/graphql-transformer-interfaces/src/transformer-context/index.ts(2,3): error TS1205: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'. ../../../../../node_modules/@aws-amplify/graphql-transformer-interfaces/src/transformer-context/index.ts(3,3): error TS1205: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'. ../../../../../node_modules/@aws-amplify/graphql-transformer-interfaces/src/transformer-context/index.ts(5,3): error TS1205: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'. ../../../../../node_modules/@aws-amplify/graphql-transformer-interfaces/src/transformer-context/index.ts(7,10): error TS1205: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'. ../../../../../node_modules/@aws-amplify/graphql-transformer-interfaces/src/transformer-context/index.ts(8,10): error TS1205: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'. ../../../../../node_modules/@aws-amplify/graphql-transformer-interfaces/src/transformer-context/index.ts(9,10): error TS1205: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'. ../../../../../node_modules/@aws-amplify/graphql-transformer-interfaces/src/transformer-context/index.ts(9,39): error TS1205: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'. ../../../../../node_modules/@aws-amplify/graphql-transformer-interfaces/src/transformer-context/index.ts(12,3): error TS1205: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'. ../../../../../node_modules/@aws-amplify/graphql-transformer-interfaces/src/transformer-context/index.ts(13,3): error TS1205: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'. ../../../../../node_modules/@aws-amplify/graphql-transformer-interfaces/src/transformer-context/index.ts(14,3): error TS1205: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'. ../../../../../node_modules/@aws-amplify/graphql-transformer-interfaces/src/transformer-context/index.ts(15,3): error TS1205: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'. ../../../../../node_modules/@aws-amplify/graphql-transformer-interfaces/src/transformer-context/index.ts(16,3): error TS1205: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'. ../../../../../node_modules/@aws-amplify/graphql-transformer-interfaces/src/transformer-context/index.ts(17,3): error TS1205: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'. ../../../../../node_modules/@aws-amplify/graphql-transformer-interfaces/src/transformer-context/index.ts(19,10): error TS1205: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'. ../../../../../node_modules/@aws-amplify/graphql-transformer-interfaces/src/transformer-context/index.ts(20,10): error TS1205: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'. ../../../../../node_modules/@aws-amplify/graphql-transformer-interfaces/src/transformer-context/index.ts(21,10): error TS1205: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'. at makeError (/snapshot/repo/build/node_modules/execa/lib/error.js:60:11) at Function.sync (/snapshot/repo/build/node_modules/execa/index.js:194:17) at buildResource (/snapshot/repo/build/node_modules/@aws-amplify/amplify-category-custom/lib/utils/build-custom-resources.js:100:25) at runMicrotasks () at processTicksAndRejections (internal/process/task_queues.js:95:5) at async buildCustomResources (/snapshot/repo/build/node_modules/@aws-amplify/amplify-category-custom/lib/utils/build-custom-resources.js:43:13) at async transformCategoryStack (/snapshot/repo/build/node_modules/@aws-amplify/amplify-category-custom/lib/index.js:54:5) at async transformResourceWithOverrides (/snapshot/repo/build/node_modules/amplify-provider-awscloudformation/lib/override-manager/transform-resource.js:80:9) at async Object.buildOverrides (/snapshot/repo/build/node_modules/amplify-provider-awscloudformation/lib/utility-functions.js:106:7) at async buildOverridesEnabledResources (/snapshot/repo/build/node_modules/amplify-provider-awscloudformation/lib/build-override-enabled-resources.js:31:3) at async Object.run (/snapshot/repo/build/node_modules/amplify-provider-awscloudformation/lib/initialize-env.js:109:3) ```

Additional information

No response

josefaidt commented 2 years ago

Hey @acusti :wave: thanks for raising this! To better understand the context of the issue what is the motivation behind adding the custom resource to the list of workspaces in your project?

LoukasGP commented 1 year ago

Has a solution been created for this? I'm also experiencing the same issue.

AWS Amplify Code Build Error Message:


2023-01-07T09:31:46.487Z [INFO]: info  - Checking validity of types...
2023-01-07T09:31:46.689Z [INFO]: We detected TypeScript in your project and reconfigured your tsconfig.json file for you. Strict-mode is set to false by default.
2023-01-07T09:31:46.690Z [INFO]: The following mandatory changes were made to your tsconfig.json:
                                 - isolatedModules was set to true (requirement for SWC / Babel)
2023-01-07T09:31:51.467Z [WARNING]: Failed to compile.
2023-01-07T09:31:51.468Z [WARNING]: ./amplify/backend/node_modules/@aws-amplify/graphql-transformer-interfaces/src/index.ts:2:10
                                    Type error: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'.
                                      1 | export * from './transformer-context';
                                    > 2 | export { TransformerPluginProvider, TransformerPluginType } from './transformer-plugin-provider';
                                        |          ^
                                      3 | export {
                                      4 |   MutationFieldType,
                                      5 |   QueryFieldType,
2023-01-07T09:31:51.495Z [ERROR]: !!! Build failed
2023-01-07T09:31:51.495Z [ERROR]: !!! Non-Zero Exit Code detected

This started when I introduced Cypress testing. Deployment was successful before.

Package.json:

  "dependencies": {
    "@aws-amplify/cli-extensibility-helper": "^2.3.33",
    "@aws-amplify/ui-react": "^3.4.1",
    "@emotion/cache": "^11.7.1",
    "@emotion/react": "^11.7.1",
    "@emotion/server": "^11.4.0",
    "@emotion/styled": "^11.6.0",
    "@mui/icons-material": "^5.2.4",
    "@mui/material": "^5.2.4",
    "@mui/x-date-pickers": "^5.0.0-alpha.2",
    "aos": "^2.3.4",
    "aws-amplify": "^4.3.45",
    "aws-cdk-lib": "^2.49.0",
    "card-validator": "^8.1.1",
    "date-fns": "^2.28.0",
    "dotenv": "^16.0.1",
    "express-jwt": "^7.7.5",
    "formik": "^2.2.6",
    "jarallax": "^1.12.8",
    "jwks-rsa": "^2.1.4",
    "ksuid": "^3.0.0",
    "next": "12.1.5",
    "next-global-css": "^1.3.1",
    "nextjs-progressbar": "0.0.14",
    "prop-types": "^15.7.2",
    "react": "^17.0.2",
    "react-countup": "^6.1.0",
    "react-dom": "^17.0.2",
    "react-image-lightbox": "^5.1.4",
    "react-slick": "^0.28.1",
    "react-syntax-highlighter": "^15.4.5",
    "react-visibility-sensor": "^5.1.1",
    "sharp": "^0.30.7",
    "slick-carousel": "^1.8.1",
    "yup": "^0.32.11"
  },
  "devDependencies": {
    "@next/eslint-plugin-next": "^12.1.6",
    "@typescript-eslint/eslint-plugin": "^5.7.0",
    "@typescript-eslint/parser": "^5.7.0",
    "aws-sdk": "^2.1135.0",
    "babel-eslint": "^10.1.0",
    "babel-plugin-styled-components": "^2.0.2",
    "cross-env": "^7.0.2",
    "cypress": "^12.3.0",
    "eslint": "^8.4.1",
    "eslint-config-next": "^12.1.6",
    "eslint-config-react-app": "^7.0.0",
    "eslint-plugin-flowtype": "^8.0.3",
    "eslint-plugin-jsx-a11y": "^6.5.1",
    "eslint-plugin-prettier": "^4.0.0",
    "eslint-plugin-react": "^7.27.1",
    "eslint-plugin-react-hooks": "^4.3.0",
    "prettier": "^2.5.1",
    "prettier-eslint": "^13.0.0",
    "prettier-eslint-cli": "^5.0.0",
    "rimraf": "^3.0.2",
    "typescript": "^4.9.4"
  }
mehrdad-shokri commented 11 months ago

I'm having the same problem with ^6.0.5