Amplify-js: Can't resolve '@aws-amplify/analytics'

Created on 19 Oct 2018  路  12Comments  路  Source: aws-amplify/amplify-js

Describe the bug
Trying to run npm run start with the (at the moment) latest stable versions of aws-amplify and aws-amplify-react and get this error message:


Failed to compile.
./node_modules/aws-amplify-react/dist/Analytics/trackUpdate.js

Module not found: Can't resolve '@aws-amplify/analytics' in ' ... node_modules/aws-amplify-react/dist/Analytics'


To Reproduce
Steps to reproduce the behavior:

  1. Get the latest stable versions of aws-amplify and aws-amplify-react. I am using:
    aws-amplify: 1.1.7,
    aws-amplify-react: 2.1.1
  1. npm run start in terminal

Expected behavior
The application to run and build without errors

Desktop (please complete the following information):

  • OS: [Mac OS High Sierra version 10.13.6]
  • Browser [chrome]

Additional context
Application created with react-scripts-ts version 2.16.0.
Works with
aws-amplify: 1.1.4
aws-amplify-react: 2.1.1

investigating

Most helpful comment

@darthmayhem How Upgrade your AWS-SDK solve the issue? This is somewhat related to aws-amplify-react only which explicitly require us to include @aws-amplify/analytics which we don't want to. That's why I'm asking

Why is it still needed? Does aws-amplify-react needs it for something else?

If someone can answer the above question, then I will be happy to include it to my build.

All 12 comments

Hi @karlmosenbacher

Can you share a little bit more code? (e.g. how are you configuring Amplify).

I am having trouble reproducing the issue, this is what I am doing and I can see analytics events being logged:

npx create-react-app my-app [email protected]
cd my-app
npm i [email protected] [email protected]
npm run start

App.tsx:

import Amplify, { Analytics } from "aws-amplify";
import aws_exports from "./aws-exports";
Amplify.configure(aws_exports);

Analytics.record({ name: 'anEvent' });

@manueliglesias thanks for the answer, but the thing is that I don't even use analytics in my application at all.

Below is how I configure amplify

Amplify.configure({
  Auth: {
    region: appRegion,
    userPoolId: appUserPoolId,
    userPoolWebClientId: appClientId,
  }
});

and thats it. The only module I am using is the Auth module from the aws-amplify library and the authenticator component from aws-amplify-react.

Same issue, I reinstalled with these versions as suggested by @manueliglesias

npm i [email protected] [email protected]

@dani-media Im glad Im not the only one with this issue, and I was still investigating if I have done something wrong.
@manueliglesias Did you manage to re-produce the issue?

@dani-media Solved it by creating a new project with react-script-ts and copied over the source-folder. I dont really know what the underlying problem was...

For what it's worth I had this exact same error and realized aws-amplify wasn't in my package.json. I think I just assumed it would be due to the amplify init call I'd made from the CLI.

You may have missed:

yarn add aws-amplify

(or the npm equivalent)

It's in the docs, but easy to miss

Hi. I'm also experiencing the same issue. I'm using this example as a base and it works as expected. However, thanks to the introduction of modular approach, I was able to reduced the bundled size. I only need @aws-amplify/core and @aws-amplify/auth for the aws-amplify-react but it still needs @aws-amplify/analytics.

Why is it still needed? Does aws-amplify-react needs it for something else?

By the way, I updated all dependencies to latest.

See below sample code.

import React, { Component } from 'react';
import logo from './logo.svg';
import './App.css';
import { withAuthenticator } from 'aws-amplify-react';
import Amplify from '@aws-amplify/core';
import Auth from '@aws-amplify/auth';

Amplify.configure({
    Auth: {
       identityPoolId: 'XX-XXXX-X:XXXXXXXX-XXXX-1234-abcd-1234567890ab', //REQUIRED - Amazon Cognito Identity Pool ID
        region: 'XX-XXXX-X', // REQUIRED - Amazon Cognito Region
        userPoolId: 'XX-XXXX-X_abcd1234', //OPTIONAL - Amazon Cognito User Pool ID
        userPoolWebClientId: 'XX-XXXX-X_abcd1234', //OPTIONAL - Amazon Cognito Web Client ID
    }
});

class App extends Component {
  render() {
    return (
      <div className="App">
        <header className="App-header">
          <img src={logo} className="App-logo" alt="logo" />
          <h1 className="App-title">Welcome to React</h1>
        </header>
        <p className="App-intro">
          To get started, edit <code>src/App.js</code> and save to reload.
        </p>
      </div>
    );
  }
}

export default withAuthenticator(App);

Upgrade your AWS-SDK.

@darthmayhem How Upgrade your AWS-SDK solve the issue? This is somewhat related to aws-amplify-react only which explicitly require us to include @aws-amplify/analytics which we don't want to. That's why I'm asking

Why is it still needed? Does aws-amplify-react needs it for something else?

If someone can answer the above question, then I will be happy to include it to my build.

This issue appeared after I updated my mac OS. This also broke git. Solution here: https://stackoverflow.com/questions/52522565/git-is-not-working-after-macos-update-xcrun-error-invalid-active-developer-pa

I have the same question as @ricxsar
Just bumped into this issue and updating the SDK didn't solve it.

Was this page helpful?
0 / 5 - 0 ratings