简体   繁体   中英

Trying out AWS-Amplify -> “npm start” not working

To better know how to use AWS-Amplify I am following this document .

It all goes well, until I reach the point ( Step 4. Integrate AWS Resources ) where after modifying src/app.js I want to run this command:

$ npm start

and then hopefully look (in the browser) at:

http://localhost:8080/

But here is what happens when running npm start

$ npm start

> amplify-js-app@1.0.0 start /Users/myaccount/amplify-js-app
> webpack && webpack-dev-server --mode development

Hash: xyzaghs789
Version: webpack 4.33.0
Time: 116ms
Built at: 06/10/2019 11:03:49 PM
         Asset      Size  Chunks             Chunk Names
    index.html  1.55 KiB          [emitted]  
main.bundle.js  28.9 KiB    main  [emitted]  main
Entrypoint main = main.bundle.js
[./src/app.js] 145 bytes {main} [built] [failed] [1 error]

ERROR in ./src/app.js 26:0
Module parse failed: Unexpected token (26:0)
You may need an appropriate loader to handle this file type.
|     });
| 
> 
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! amplify-js-app@1.0.0 start: `webpack && webpack-dev-server --mode development`
npm ERR! Exit status 2
npm ERR! 
npm ERR! Failed at the amplify-js-app@1.0.0 start script.
npm ERR! This is probably not a problem with npm. 
There is likely additional logging output above.
......
$

Since nothing is my own code here, only what I got from the document linked above. I would guess other people have also hit the same issue at some point.

Is there anything I can do to solve this problem? (Which anyone knows of)

Just for reference, here is the contents of ./src/app.js , copied from the link mentioned above:

import Auth from '@aws-amplify/auth';
import Analytics from '@aws-amplify/analytics';

import awsconfig from './aws-exports';

// retrieve temporary AWS credentials and sign requests
Auth.configure(awsconfig);
// send analytics events to Amazon Pinpoint
Analytics.configure(awsconfig);

const AnalyticsResult = document.getElementById('AnalyticsResult');
const AnalyticsEventButton = document.getElementById('AnalyticsEventButton');
let EventsSent = 0;

AnaltyicsEventButton.addEventListener('click', (event) => {
  const { aws_mobile_analytics_app_region, aws_mobile_analytics_app_id } = awsconfig;

  Analytics.record('Amplify Tutorial Event')
    .then((event) => {
      const url = `https://${aws_mobile_analytics_app_region}.console.aws.amazon.com/pinpoint/home/?region=${aws_mobile_analytics_app_region}#/apps/${aws_mobile_analytics_app_id}/analytics/events`;
      AnalyticsResult.innerHTML = '<p>Event Submitted. </p>';
      AnalyticsResult.innerHTML += '<p>Events sent: '+(++EventsSent)+'</p>';
      AnalyticsResult.innerHTML += '<a href="'+url+'" target="_blank">View Events on the Amazon Pinpoint Console</a>';
    });

Just in case someone else happens to hit the same issue. This (curly brace and paranthese):

});

is missing at the end of the ./src/app.js, file in the document .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM