简体   繁体   English

AWS Amplify 与 Nuxt.js - 参考错误:导航器未定义

[英]AWS Amplify with Nuxt.js - Reference Error: Navigator is not defined

I'm trying to use Nuxt.js with AWS Amplify for SSR/SEO benefits.我正在尝试将 Nuxt.js 与 AWS Amplify 一起使用以获得 SSR/SEO 优势。

I'm able to get Amplify added to my project and have successfully configured Amplify using the "Manual Configuration" steps described in the Amplify Docs.我能够将 Amplify 添加到我的项目中,并使用 Amplify 文档中描述的“手动配置”步骤成功配置了 Amplify。 I was even able to get basic SignUp, SignIn methods working.我什至能够让基本的 SignUp、SignIn 方法正常工作。

However, after refreshing the app I receive the below error.但是,刷新应用程序后,我收到以下错误。 I believe this is because of the SSR aspect of Nuxt as referenced in this old Stack overflow thread .我相信这是因为在这个旧的堆栈溢出线程中引用的 Nuxt 的 SSR 方面。

The thread above mentions adding this line:上面的线程提到添加这一行:

global.navigator = () => null;

However I have no idea where to add this.但是我不知道在哪里添加这个。

Error Details:错误详情:

ReferenceError: navigator is not defined ReferenceError:未定义导航器

File: node_modules/@aws-amplify/analytics/dist/aws-amplify-analytics.js文件:node_modules/@aws-amplify/analytics/dist/aws-amplify-analytics.js

Place in the code, (line 38103):放入代码中(第 38103 行):

var logger = new _aws_amplify_core__WEBPACK_IMPORTED_MODULE_0__["ConsoleLogger"]('AWSPinpointProvider');
var RETRYABLE_CODES = [429, 500];
var ACCEPTED_CODES = [202];
var MOBILE_SERVICE_NAME = 'mobiletargeting';
var BEACON_SUPPORTED = navigator && typeof navigator.sendBeacon === 'function'; // events buffer

var BUFFER_SIZE = 1000;
var FLUSH_SIZE = 100;
var FLUSH_INTERVAL = 5 * 1000; // 5s

If you want to execute only on client side wrap it in如果您只想在客户端执行,请将其包装在

if(process.server){
    //Code
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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