为了更好地了解如何使用AWS-Amplify
,我关注了this document。
一切顺利,直到到达修改src / app.js之后要运行此命令的地步(步骤4。集成AWS资源)。
$ 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>';
});