Appcenter-sdk-react-native: Cannot compile project with TypeScript `--isolatedModules` enabled

Created on 21 Oct 2019  路  4Comments  路  Source: microsoft/appcenter-sdk-react-native

Description

I am trying to build our React Native project using the guidelines described here:
https://facebook.github.io/react-native/docs/typescript#adding-typescript-to-an-existing-project
The major issue is when enabling isolatedModules. Our code imports the following from the AppCenter React Native SDK:

import AppCenter from "appcenter";
import Crashes, { ErrorAttachmentLog } from "appcenter-crashes";

When I run the TypeScript compiler, I get the following errors:

yarn run v1.15.2
$ tsc
node_modules/appcenter-crashes/Crashes.d.ts:1:19 - error TS1209: Ambient const enums are not allowed when the '--isolatedModules' flag is provided.

1 export const enum UserConfirmation {
                    ~~~~~~~~~~~~~~~~

node_modules/appcenter/AppCenter.d.ts:1:19 - error TS1209: Ambient const enums are not allowed when the '--isolatedModules' flag is provided.

1 export const enum LogLevel {
                    ~~~~~~~~

node_modules/appcenter/AppCenter.d.ts:14:19 - error TS1209: Ambient const enums are not allowed when the '--isolatedModules' flag is provided.

14 export const enum AppCenterLogLevel {
                     ~~~~~~~~~~~~~~~~~

error Command failed with exit code 1.

From my searching online, it appears that library declarations need to avoid const enum so they can be used with or without the isolatedModules flag. Since this flag is now recommended by the React Native TypeScript guidelines, it is something the AppCenter SDK needs to support.

Repro Steps

Please list the steps used to reproduce your issue.

  1. Create a React Native project (0.57 or later) and enable the TypeScript integration
  2. Add a .ts file that imports artifacts from "appcenter" and "appcenter-crashes".
  3. Typecheck the project (e.g. yarn tsc)

Details

  1. Which version of the App Center SDK are you using?
    1.12.0
  2. Which OS version did you experience the issue on?
    N/A
  3. What device version did you see this error on? Were you using an emulator or a physical device?
    N/A
  4. What third party libraries are you using?
    React Native 0.57, TypeScript 3.1
  5. Run the following command and paste the output below: react-native info
  React Native Environment Info:
    System:
      OS: macOS 10.14.6
      CPU: x64 Intel(R) Core(TM) i7-8850H CPU @ 2.60GHz
      Memory: 9.03 GB / 32.00 GB
      Shell: 3.2.57 - /bin/bash
    Binaries:
      Node: 8.11.4 - /var/folders/x5/9543yn1n4hg2cyk_9bzgfcdh0000gp/T/yarn--1571674717580-0.39145863065495035/node
      Yarn: 1.15.2 - /var/folders/x5/9543yn1n4hg2cyk_9bzgfcdh0000gp/T/yarn--1571674717580-0.39145863065495035/yarn
      npm: 5.6.0 - ~/.nvm/versions/node/v8.11.4/bin/npm
    SDKs:
      iOS SDK:
        Platforms: iOS 12.1, macOS 10.14, tvOS 12.1, watchOS 5.1
      Android SDK:
        Build Tools: 23.0.1, 23.0.3, 25.0.0, 25.0.1, 25.0.2, 25.0.3, 26.0.2, 26.0.3, 27.0.0, 27.0.3, 28.0.2, 28.0.3, 29.0.0, 29.0.2
        API Levels: 21, 22, 25, 26, 27, 28
    IDEs:
      Android Studio: 3.1 AI-173.4907809
      Xcode: 10.1/10B61 - /usr/bin/xcodebuild
    npmPackages:
      @types/react: 16.7.3 => 16.7.3 
      @types/react-native: 0.57.19 => 0.57.19 
      react: 16.6.3 => 16.6.3 
      react-native: ^0.57.0 => 0.57.8 
    npmGlobalPackages:
      react-native-create-library: 3.1.2
  1. If you're developing for React Native iOS, run the following command and paste the output below: pod --version

N/A

  1. Please enable verbose logging for your app using [MSAppCenter setLogLevel: MSLogLevelVerbose]; before your call to [AppCenterReactNative register]; (or any other SDK registration). For Android, use AppCenter.setLogLevel(android.util.Log.VERBOSE); before your SoLoader.init call (you will need to import com.microsoft.appcenter.AppCenter;). Include the logs here:

N/A

bug

Most helpful comment

@dhei I can confirm that upgrading to TypeScript 3.4.5 allows us to run tsc without the --skipLibCheck flag. Thank you for the advice.

All 4 comments

Hi @newyankeecodeshop,

Thanks for reporting this issue to us. We are fixing this issue.

Do you mind sharing your tsconfig with us?

PS: Looks like TypeScript v3.4.5 no longer make this an error, upgrading to TypeScript v3.4.5 or later is probably a workaround at this moment.

Thanks @dhei ,

I'll try upgrading to TypeScript 3.4 to see if that helps us. We've been meaning to upgrade anyway.
Here is our tsconfig:

  "compilerOptions": {
    "allowJs": true,
    "allowSyntheticDefaultImports": true,
    "baseUrl": ".",
    "paths": {
      "*": ["src/*"],
      "tests": ["tests/*"]
    },
    "esModuleInterop": true,
    "isolatedModules": true,
    "moduleResolution": "node",
    "target": "esnext",
    "lib": ["es2017"],
    "jsx": "react",
    "noEmit": true,
    "noUnusedLocals": true,
    "noImplicitAny": false,
    "noImplicitReturns": true,
    "strict": true,
    "strictFunctionTypes": false,
    "preserveConstEnums": true,
    "sourceMap": true,
  },

@dhei I can confirm that upgrading to TypeScript 3.4.5 allows us to run tsc without the --skipLibCheck flag. Thank you for the advice.

Hey!
We've included fixes in the latest SDK release for this. I'm closing the issue but please reopen if you run into this again.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

celso-henrique picture celso-henrique  路  9Comments

CodyBrouwers picture CodyBrouwers  路  4Comments

rafaelcorreiapoli picture rafaelcorreiapoli  路  5Comments

aprilmintacpineda picture aprilmintacpineda  路  5Comments

rskapadiadev picture rskapadiadev  路  7Comments