aws-amplify / learn

AWS Amplify Learn
https://amplify.aws/learn/
Apache License 2.0
266 stars 117 forks source link

Unable to Run Locally #2

Closed ahmadawais closed 5 years ago

ahmadawais commented 5 years ago

Howdy, folks!

Awesome resource. I'd love to help with the site and start a meetup.

Have a couple of things I wanted to fix but am still unable to run the site locally with yarn start.

ENTIRE LOG (CLICK TO EXPAND!) ```sh success open and validate gatsby-configs — 0.189 s success load plugins — 0.284 s success onPreInit — 0.948 s success initialize cache — 0.017 s success copy gatsby files — 0.103 s success onPreBootstrap — 0.014 s success source and transform nodes — 0.577 s success building schema — 0.417 s success createPages — 0.100 s success createPagesStatefully — 0.029 s success onPreExtractQueries — 0.003 s success update schema — 0.054 s warning The GraphQL query in the non-page component "/Users/ahmadawais/Documents/Web/Sandbox/awsamplify/src/templates/Event.js" will not be run. warning The GraphQL query in the non-page component "/Users/ahmadawais/Documents/Web/Sandbox/awsamplify/src/templates/Post.js" will not be run. Exported queries are only executed for Page components. It's possible you're trying to create pages in your gatsby-node.js and that's failing for some reason. If the failing component(s) is a regular component and not intended to be a page component, you generally want to use a (https://gatsbyjs.org/docs/static-query) instead of exporting a page query. If you're more experienced with GraphQL, you can also export GraphQL fragments from components and compose the fragments in the Page component query and pass data down into the child component — http://graphql.org/learn/queries/#fragments success extract queries from components — 0.184 s success run graphql queries — 7.802 s — 43/43 5.51 queries/second success write out page data — 0.005 s success write out redirect data — 0.001 s Generating image thumbnails [==============================] 422/422 80.6 secs 100% warning The icon(/Users/ahmadawais/Documents/Web/Sandbox/awsamplify/src/assets/images/icon.png) you provided to 'gatsby-plugin-manifest' is not square. The icons we generate will be square and for the best results we recommend you provide a square icon. success onPostBootstrap — 0.431 s info bootstrap finished - 87.426 s ERROR Failed to compile with 1 errors 8:41:23 PM This relative module was not found: * ../aws-exports in ./src/utilities/track.js ✖ 「wdm」: ERROR in ./src/utilities/track.js Module not found: Error: Can't resolve '../aws-exports' in '/Users/ahmadawais/Documents/Web/Sandbox/awsamplify/src/utilities' @ ./src/utilities/track.js 9:0-39 15:22-31 @ ./src/utilities/index.js @ ./src/templates/Contributor.js @ ./.cache/sync-requires.js @ ./.cache/app.js @ multi event-source-polyfill (webpack)-hot-middleware/client.js?path=/__webpack_hmr&reload=true&overlay=false ./.cache/app ℹ 「wdm」: Failed to compile. ```

Send halp :)

ahmadawais commented 5 years ago

It the track.js file!


import Amplify, {Analytics} from 'aws-amplify';
- import awsmobile from '~/aws-exports'; // ← This is missing!
import {curry} from 'ramda';

// wiped on page refresh / non-pwa redirects
let configured = false;

const track = curry((name, attributes) => {
  if (!configured) {
    Amplify.configure(awsmobile);
    configured = true;
  }

  Analytics.record({name, attributes});
});

export const internalPageView = props =>
  track('internal page view', {href: props.location.href});
export const externalPageView = href => track('external page view', {href});
wizage commented 5 years ago

This project works using the Amplify CLI. To run a local copy you have to make a copy of the backend. So after cloning the repo you can run these commands:

amplify env add
? Do you want to use an existing environment? No
? Enter a name for the environment mysandbox
// Rest of init steps (around your AWS account)
$ amplify push

This setups up your own backend in AWS and also creates the aws-exports file when it is complete. You can read more about how multi-env works here.

ahmadawais commented 5 years ago

So to work on a simple PR I'll have to create an entire backend in AWS in my personal account? That doesn't feel very nice. Is there a possibility of avoiding all that?

harrysolovay commented 5 years ago

Hi @ahmadawais –– thank you for filing this issue. It’s been fixed. Please let us know if you run into any more trouble.

ahmadawais commented 5 years ago

I can confirm, I am able to run locally without any changes now.

Thank you! 👌