首页 > 解决方案 > 试用 AWS-Amplify ->“npm start”不起作用

问题描述

为了更好地了解如何使用,AWS-Amplify我正在关注此文档

一切顺利,直到我到达修改 src/app.js 后我想运行此命令的点(步骤 4. Integrate AWS Resources ):

$ npm start

然后希望(在浏览器中)查看:

http://localhost:8080/

但这是运行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.
......
$

因为这里没有我自己的代码,只有我从上面链接的文档中得到的。我猜其他人在某些时候也遇到了同样的问题。

我能做些什么来解决这个问题吗?(谁都知道)

仅供参考,这里是./src/app.js的内容,从上面提到的链接复制:

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>';
    });

标签: javascriptnode.jsamazon-web-servicesaws-amplify

解决方案


以防万一其他人碰巧遇到同样的问题。这(花括号和括号):

});

在 ./src/app.js, 文件的末尾缺少文件


推荐阅读