aws-amplify / amplify-js

A declarative JavaScript library for application development using cloud services.
https://docs.amplify.aws/lib/q/platform/js
Apache License 2.0
9.42k stars 2.12k forks source link

Type error: Re-exporting a type when 'isolatedModules' is enabled requires using 'export type'. #12715

Closed Meags27 closed 8 months ago

Meags27 commented 9 months ago

Before opening, please confirm:

JavaScript Framework

Next.js

Amplify APIs

Not applicable

Amplify Categories

Not applicable

Environment information

``` # Put output below this line System: OS: Windows 10 10.0.19045 CPU: (16) x64 11th Gen Intel(R) Core(TM) i9-11900K @ 3.50GHz Memory: 41.71 GB / 63.82 GB Binaries: Node: 18.17.1 - C:\Program Files\nodejs\node.EXE npm: 10.1.0 - C:\Program Files\nodejs\npm.CMD Browsers: Edge: Chromium (120.0.2210.77) Internet Explorer: 11.0.19041.3636 npmPackages: @ampproject/toolbox-optimizer: undefined () @aws-amplify/adapter-nextjs: ^1.0.7 => 1.0.7 @aws-amplify/adapter-nextjs/api: undefined () @aws-amplify/adapter-nextjs/data: undefined () @aws-sdk/client-cognito-identity-provider: ^3.473.0 => 3.473.0 @aws-sdk/client-s3: ^3.473.0 => 3.473.0 @aws-sdk/s3-request-presigner: ^3.473.0 => 3.473.0 @babel/core: undefined () @babel/runtime: 7.22.5 @edge-runtime/cookies: 4.0.2 @edge-runtime/ponyfill: 2.4.1 @edge-runtime/primitives: 4.0.2 @hapi/accept: undefined () @headlessui/react: ^1.7.17 => 1.7.17 @mswjs/interceptors: undefined () @napi-rs/triples: undefined () @next/font: undefined () @next/react-dev-overlay: undefined () @opentelemetry/api: undefined () @react-email/button: 0.0.10 => 0.0.10 @react-email/html: 0.0.4 => 0.0.4 @react-email/render: ^0.0.7 => 0.0.7 (0.0.6) @segment/ajv-human-errors: undefined () @types/node: ^20.10.4 => 20.10.4 (12.20.55) @types/react: ^18.2.45 => 18.2.45 @types/react-dom: ^18.2.17 => 18.2.17 @types/validator: ^13.11.7 => 13.11.7 @vercel/nft: undefined () @vercel/og: 0.5.15 acorn: undefined () amphtml-validator: undefined () anser: undefined () arg: undefined () assert: undefined () async-retry: undefined () async-sema: undefined () autoprefixer: ^10.4.16 => 10.4.16 aws-amplify: ^6.0.7 => 6.0.7 aws-amplify/adapter-core: undefined () aws-amplify/analytics: undefined () aws-amplify/analytics/kinesis: undefined () aws-amplify/analytics/kinesis-firehose: undefined () aws-amplify/analytics/personalize: undefined () aws-amplify/analytics/pinpoint: undefined () aws-amplify/api: undefined () aws-amplify/api/server: undefined () aws-amplify/auth: undefined () aws-amplify/auth/cognito: undefined () aws-amplify/auth/cognito/server: undefined () aws-amplify/auth/server: undefined () aws-amplify/datastore: undefined () aws-amplify/in-app-messaging: undefined () aws-amplify/in-app-messaging/pinpoint: undefined () aws-amplify/push-notifications: undefined () aws-amplify/push-notifications/pinpoint: undefined () aws-amplify/storage: undefined () aws-amplify/storage/s3: undefined () aws-amplify/storage/s3/server: undefined () aws-amplify/storage/server: undefined () aws-amplify/utils: undefined () aws-jwt-verify: ^4.0.0 => 4.0.0 babel-packages: undefined () browserify-zlib: undefined () browserslist: undefined () buffer: undefined () bytes: undefined () ci-info: undefined () cli-select: undefined () client-only: 0.0.1 comment-json: undefined () compression: undefined () conf: undefined () constants-browserify: undefined () content-disposition: undefined () content-type: undefined () cookie: undefined () cross-spawn: undefined () crypto-browserify: undefined () css.escape: undefined () data-uri-to-buffer: undefined () debug: undefined () devalue: undefined () domain-browser: undefined () edge-runtime: undefined () encoding: ^0.1.13 => 0.1.13 eslint: ^8.55.0 => 8.55.0 eslint-config-next: ^13.5.6 => 13.5.6 events: undefined () find-cache-dir: undefined () find-up: undefined () fresh: undefined () get-orientation: undefined () glob: undefined () gzip-size: undefined () http-proxy: undefined () http-proxy-agent: undefined () https-browserify: undefined () https-proxy-agent: undefined () icss-utils: undefined () ignore-loader: undefined () image-size: undefined () is-animated: undefined () is-docker: undefined () is-wsl: undefined () jest-worker: undefined () json5: undefined () jsonwebtoken: undefined () loader-runner: undefined () loader-utils: undefined () lodash.curry: undefined () lru-cache: undefined () micromatch: undefined () mini-css-extract-plugin: undefined () nanoid: undefined () native-url: undefined () neo-async: undefined () next: ^14.0.4 => 14.0.4 node-fetch: undefined () node-html-parser: undefined () ora: undefined () os-browserify: undefined () p-limit: undefined () path-browserify: undefined () platform: undefined () postcss: ^8.4.32 => 8.4.32 (8.4.31) postcss-flexbugs-fixes: undefined () postcss-modules-extract-imports: undefined () postcss-modules-local-by-default: undefined () postcss-modules-scope: undefined () postcss-modules-values: undefined () postcss-preset-env: undefined () postcss-safe-parser: undefined () postcss-scss: undefined () postcss-value-parser: undefined () process: undefined () punycode: undefined () qrcode.react: ^3.1.0 => 3.1.0 querystring-es3: undefined () raw-body: undefined () react: ^18.2.0 => 18.2.0 react-builtin: undefined () react-dom: ^18.2.0 => 18.2.0 react-dom-builtin: undefined () react-dom-experimental-builtin: undefined () react-email: 1.9.4 => 1.9.4 react-experimental-builtin: undefined () react-icons: ^4.12.0 => 4.12.0 react-is: 18.2.0 react-refresh: 0.12.0 react-server-dom-turbopack-builtin: undefined () react-server-dom-turbopack-experimental-builtin: undefined () react-server-dom-webpack-builtin: undefined () react-server-dom-webpack-experimental-builtin: undefined () regenerator-runtime: 0.13.4 sass-loader: undefined () scheduler-builtin: undefined () scheduler-experimental-builtin: undefined () schema-utils: undefined () semver: undefined () send: undefined () server-only: ^0.0.1 => 0.0.1 setimmediate: undefined () shell-quote: undefined () source-map: undefined () stacktrace-parser: undefined () stream-browserify: undefined () stream-http: undefined () string-hash: undefined () string_decoder: undefined () strip-ansi: undefined () stripe: ^14.8.0 => 14.8.0 superstruct: undefined () tailwindcss: ^3.3.6 => 3.3.6 tar: undefined () terser: undefined () text-table: undefined () timers-browserify: undefined () tty-browserify: undefined () typescript: ^5.3.3 => 5.3.3 ua-parser-js: undefined () unistore: undefined () util: undefined () validator: ^13.11.0 => 13.11.0 vm-browserify: undefined () watchpack: undefined () web-vitals: undefined () webpack: undefined () webpack-sources: undefined () ws: undefined () zod: ^3.22.4 => 3.22.4 () npmGlobalPackages: @aws-amplify/cli: 10.8.1 npm: 10.1.0 ```

Describe the bug

Trying to build a production next.js server with npm run build but have this error from aws-amplify library.


./node_modules/@aws-amplify/core/src/clients/index.ts:12:2
Type error: Re-exporting a type when 'isolatedModules' is 
enabled requires using 'export type'.

  10 |  getHashedPayload,
  11 |  presignUrl,
> 12 |  PresignUrlOptions,
     |  ^
  13 |  signRequest,
  14 |  SignRequestOptions,
  15 | } from './middleware/signing/signer/signatureV4';

If I try turning isolatedModules to false, it just auto puts it back to true afterwards with this message:

"We detected TypeScript in your project and reconfigured your tsconfig.json file for you. Strict-mode is set to false by default. The following mandatory changes were made to your tsconfig.json:

        - isolatedModules was set to true (requirement for SWC / Babel)"

Expected behavior

Compiling a production server without an error

Reproduction steps

npm run build with amplify library and next.js

Code Snippet

// Put your code below this line.

Log output

``` // Put your logs below this line ```

aws-exports.js

No response

Manual configuration

No response

Additional configuration

tsconfig.json

{
  "compilerOptions": {
    "target": "es5",
    "lib": [
      "dom",
      "dom.iterable",
      "esnext"
    ],
    "allowJs": true,
    "skipLibCheck": true,
    "strict": true,
    "useUnknownInCatchVariables": true,
    "forceConsistentCasingInFileNames": true,
    "noEmit": true,
    "esModuleInterop": true,
    "module": "ESNext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "jsx": "preserve",
    "incremental": true,
    "removeComments": true,
    "noImplicitAny": true,
    //"noUnusedParameters": true,
    "noImplicitReturns": true,
    "allowImportingTsExtensions": true,
    //"noUnusedLocals": true,
    "plugins": [
      {
        "name": "next"
      }
    ],
    "paths": {
      "@/*": [
        "./*"
      ]
    }
  },
  "include": [
    "next-env.d.ts",
    "**/*.ts",
    "**/*.tsx",
    ".next/types/**/*.ts"
  ],
  "exclude": [
    "node_modules"
  ]
}

Mobile Device

No response

Mobile Operating System

No response

Mobile Browser

No response

Mobile Browser Version

No response

Additional information and screenshots

No response

cwomack commented 9 months ago

@Meags27, I'm having trouble reproducing this issue when creating a new Next.JS app on v6. Was this an existing app that you upgraded from v5 and then started experiencing this error with?

Meags27 commented 9 months ago

@Meags27, I'm having trouble reproducing this issue when creating a new Next.JS app on v6. Was this an existing app that you upgraded from v5 and then started experiencing this error with?

Yes it was an Amplify v5 converted to v6. If I add "type" to the amplify source code, the error goes away but I don't want to have to tweak the library. e.g

Did you still not have the issue with "isolatedModules": true, in tsconfig.json? I have to have it to true to work with Babel/SWC it seems (it auto turns it back on if I try turning it off)

export type {
    getHashedPayload,
    presignUrl,
    PresignUrlOptions,
    signRequest,
    SignRequestOptions,
} from './middleware/signing/signer/signatureV4';
alucio-echen commented 8 months ago

I am also running into this issue on a Amplify v5 project converted to v6

Meags27 commented 8 months ago

Really need this to be fixed, as I can't run a production next.js build. It's trying to get me to add the word "type" to tons of amplify files.

e.g node_modules/@aws-amplify/core/src/clients/types/index.ts I went through and added "type" but there's so many other files it wants it.

export {
    type Middleware,
    type MiddlewareHandler,
    type Request,
    type Response,
    type TransferHandler,
    type Endpoint,
} from './core';
export {
    type Headers,
    type HttpRequest,
    type HttpResponse,
    type HttpTransferHandler,
    type HttpTransferOptions,
    type ResponseBodyMixin,
} from './http';
export {
    type Credentials,
    type EndpointResolverOptions,
    type ErrorParser,
    type ServiceClientOptions,
} from './aws';

When trying to remove isolatedModules it says

We detected TypeScript in your project and reconfigured your tsconfig.json file for you. Strict-mode is set to false by default.
   The following mandatory changes were made to your tsconfig.json:

        - isolatedModules was set to true (requirement for SWC / Babel)
Meags27 commented 8 months ago

I fixed it! @alucio-echen

When I first setup v6 (right when it first came out), some of the imports didn't suggest the right directory properly when I wanted to import methods/types from the aws-amplify library. One of them being the types of the Amplify Config file, being ResourcesConfig and LegacyConfig.

I had them imported as import { LegacyConfig, ResourcesConfig,} from "@aws-amplify/core/src/singleton/types";

But it should be:

import { ResourcesConfig } from "aws-amplify";
import { LegacyConfig } from "aws-amplify/adapter-core";

So I went and changed any imports to the proper ones (the IDE now auto suggests the right one) and now the build works. I hope this helps anyone else who may come across this!

gibbsvjy007 commented 8 months ago

`node_modules/@aws-amplify/auth/src/types/index.ts:49:2 - error TS1205: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'.

49 AuthSignInOutput,


node_modules/@aws-amplify/auth/src/types/index.ts:50:2 - error TS1205: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'.

50  AuthResetPasswordOutput,

node_modules/@aws-amplify/auth/src/types/index.ts:51:2 - error TS1205: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'.

51 AuthUpdateUserAttributeOutput,


node_modules/@aws-amplify/auth/src/types/index.ts:52:2 - error TS1205: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'.

52  AuthUpdateUserAttributesOutput,

`

I am facing the similar issue while running tsc command before commiting code.

Could you please help? @Meags27

cwomack commented 8 months ago

@gibbsvjy007 and @alucio-echen, can you clarify what version you're currently on of Amplify (e.g. v6.X)? We can reopen this issue or have you create a new one if still blocked.

mehrdad-shokri commented 6 months ago

I'm on 6.0.20 and getting the error.

./node_modules/@aws-amplify/auth/src/providers/cognito/index.ts:31:2
Type error: Re-exporting a type when 'isolatedModules' is enabled requires using 'export type'.

  29 | export { autoSignIn } from './apis/autoSignIn';
  30 | export {
> 31 |  ConfirmResetPasswordInput,
     |  ^
  32 |  ConfirmSignInInput,
  33 |  ConfirmSignUpInput,
  34 |  ConfirmUserAttributeInput,
alexandr2110pro commented 4 months ago

Ok in my case my IDE autoimorted the type

import type { ChatCompletionCreateParams } from 'openai/resources/chat/completions';

be careful...

Instead of that it should be

import OpenAI from 'openai';

declare params: OpenAI.ChatCompletionCreateParams;