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.39k stars 2.11k forks source link

AWSCloudWatch - error during _safeUploadLogEvents: ReferenceError: Can't find variable: TextEncoder #10891

Open ethanj20 opened 1 year ago

ethanj20 commented 1 year ago

Before opening, please confirm:

JavaScript Framework

React Native

Amplify APIs

REST API, Push Notifications

Amplify Categories

No response

Environment information

``` System: OS: macOS 12.6.2 CPU: (4) x64 Intel(R) Core(TM) i7-5557U CPU @ 3.10GHz Memory: 274.49 MB / 16.00 GB Shell: 5.8.1 - /bin/zsh Binaries: Node: 16.19.0 - /usr/local/bin/node npm: 9.2.0 - /usr/local/bin/npm Browsers: Firefox: 108.0.2 Safari: 15.6.1 npmPackages: @aws-amplify/pushnotification: ^5.0.6 => 5.0.6 @babel/core: ^7.12.9 => 7.20.5 @react-native-async-storage/async-storage: ^1.17.7 => 1.17.11 @react-native-community/datetimepicker: 6.1.2 => 6.1.2 @react-native-community/netinfo: ^9.3.6 => 9.3.7 @react-native-community/push-notification-ios: ^1.10.1 => 1.10.1 (1.0.3) @react-native-picker/picker: ^2.4.2 => 2.4.8 @react-navigation/bottom-tabs: ^6.3.2 => 6.5.1 @react-navigation/native: ^6.0.10 => 6.1.1 @react-navigation/native-stack: ^6.6.2 => 6.9.6 HelloWorld: 0.0.1 amazon-cognito-identity-js: ^5.2.12 => 5.2.13 (6.1.0) aws-amplify: ^5.0.6 => 5.0.6 aws-amplify-react-native: ^7.0.2 => 7.0.2 dayjs: ^1.11.3 => 1.11.7 eslint: ^8.20.0 => 8.29.0 eslint-config-airbnb: ^19.0.4 => 19.0.4 eslint-config-prettier: ^8.5.0 => 8.5.0 eslint-plugin-import: ^2.26.0 => 2.26.0 eslint-plugin-jsx-a11y: ^6.6.1 => 6.6.1 eslint-plugin-react: ^7.30.1 => 7.31.11 eslint-plugin-react-hooks: ^4.6.0 => 4.6.0 eslint-plugin-react-native: ^4.0.0 => 4.0.0 expo: ~45.0.0 => 45.0.8 expo-barcode-scanner: ~11.3.0 => 11.3.0 expo-dev-client: ~1.0.1 => 1.0.1 expo-device: ~4.2.0 => 4.2.0 expo-image-picker: ~13.1.1 => 13.1.1 expo-notifications: ~0.15.4 => 0.15.4 expo-status-bar: ~1.3.0 => 1.3.0 expo-updates: ~0.13.4 => 0.13.4 hermes-inspector-msggen: 1.0.0 metro-config: ^0.73.6 => 0.73.6 (0.67.0) native-base: ^3.4.7 => 3.4.25 path: ^0.12.7 => 0.12.7 prettier: 2.7.1 => 2.7.1 prop-types: ^15.8.1 => 15.8.1 push-notifications: ^1.0.1 => 1.0.1 qs: ^6.11.0 => 6.11.0 (6.7.0) react: 17.0.2 => 17.0.2 react-dom: 17.0.2 => 17.0.2 react-error-boundary: ^3.1.4 => 3.1.4 react-native: 0.68.2 => 0.68.2 react-native-elements: ^3.4.2 => 3.4.2 react-native-pager-view: 5.4.15 => 5.4.15 react-native-safe-area-context: ^3.4.1 => 3.4.1 react-native-screens: ~3.11.1 => 3.11.1 react-native-svg: ^12.3.0 => 12.5.0 react-native-tab-view: ^3.1.1 => 3.3.4 react-native-web: 0.17.7 => 0.17.7 text-encoder: ^0.0.4 => 0.0.4 ```

Describe the bug

I am unable to send Amplify logs to CloudWatch due to a missing variable reference (TextEncoder).

Expected behavior

I would expect this variable to be defined in the package, and I would expect the logs to show up in CloudWatch in the pre-configured log streams/groups.

Reproduction steps

Run application in simulator using the code below:

Code Snippet

import { Logger, Amplify, AWSCloudWatchProvider } from 'aws-amplify';

Amplify.configure({
  Logging: {
    logGroupName: 'logger-group-test',
    logStreamName: 'logger-stream-test',
    region: 'us-east-1',
  },
  ...awsconfig,
});

const logger = new Logger('MyLogger', 'DEBUG');
Amplify.register(logger);
logger.addPluggable(new AWSCloudWatchProvider());

const handleonpress = () => {
  logger.debug('testing my logger')
  navigation.navigate('PageName');
};

Log output

``` // Put your logs below this line [ERROR] 15:05.303 AWSCloudWatch - error when calling _safeUploadLogEvents in the timer interval - ReferenceError: Can't find variable: TextEncoder at node_modules/@aws-amplify/core/lib-esm/Logger/ConsoleLogger.js:87:15 in prototype._log at node_modules/@aws-amplify/core/lib-esm/Logger/ConsoleLogger.js:170:23 in prototype.error at node_modules/@aws-amplify/core/lib-esm/Providers/AWSCloudWatchProvider.js:517:36 in __generator$argument_1 at node_modules/tslib/tslib.js:141:30 in step at node_modules/tslib/tslib.js:122:60 in at node_modules/tslib/tslib.js:113:68 in rejected ```

aws-exports.js

/* eslint-disable */
// WARNING: DO NOT EDIT. This file is automatically generated by AWS Amplify. It will be overwritten.

const awsmobile = {
    "aws_project_region": "us-east-1",
    "aws_mobile_analytics_app_id": "f52b1bf14339427ba708444e1519837b",
    "aws_mobile_analytics_app_region": "us-east-1",
    "aws_cloud_logic_custom": [
        {
            "name": "DemiAppAPI",
            "endpoint": "https://a6e5h69smf.execute-api.us-east-1.amazonaws.com/staging",
            "region": "us-east-1"
        }
    ],
    "aws_appsync_graphqlEndpoint": "https://w65ap47cl5e4zlikfma3mbdrzy.appsync-api.us-east-1.amazonaws.com/graphql",
    "aws_appsync_region": "us-east-1",
    "aws_appsync_authenticationType": "API_KEY",
    "aws_appsync_apiKey": "da2-6u5cy2oxtnfsjimkagk6xviuzy",
    "aws_cognito_identity_pool_id": "us-east-1:04e07bd3-5d07-4582-a8fa-3217e493c7c8",
    "aws_cognito_region": "us-east-1",
    "aws_user_pools_id": "us-east-1_bNtCZ4cok",
    "aws_user_pools_web_client_id": "4hj1i6du2gpnbe1v96c5n0072u",
    "oauth": {},
    "aws_cognito_username_attributes": [
        "EMAIL"
    ],
    "aws_cognito_social_providers": [],
    "aws_cognito_signup_attributes": [
        "GIVEN_NAME",
        "FAMILY_NAME",
        "BIRTHDATE",
        "PREFERRED_USERNAME"
    ],
    "aws_cognito_mfa_configuration": "OFF",
    "aws_cognito_mfa_types": [
        "SMS"
    ],
    "aws_cognito_password_protection_settings": {
        "passwordPolicyMinLength": 8,
        "passwordPolicyCharacters": [
            "REQUIRES_LOWERCASE",
            "REQUIRES_NUMBERS",
            "REQUIRES_SYMBOLS",
            "REQUIRES_UPPERCASE"
        ]
    },
    "aws_cognito_verification_mechanisms": [
        "EMAIL"
    ],
    "aws_user_files_s3_bucket": "demi-user-profile-pictures50524-staging",
    "aws_user_files_s3_bucket_region": "us-east-1"
};

export default awsmobile;

Manual configuration

No response

Additional configuration

No response

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 1 year ago

Hello @ethanj20, and thank you for opening this issue. While the CloudWatch logger exists in the JS repo, it's use case is not included in our documentation due to the feature itself needing some improvements/bugs worked out still.

Considering you were trying to use the push notification API, this might be associated with a missing polyfill on React Native. Marking this and the related issue #9575 as bugs to increase the priority on them.

RemyNtshaykolo commented 12 months ago

Hello, This temporary fix seems to solve the problem: https://github.com/facebook/hermes/issues/948#issuecomment-1484240071