参考错误:未使用 nextjs 定义导航器 [英] Reference Error:Navigator not defined with nextjs

查看:50
本文介绍了参考错误:未使用 nextjs 定义导航器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码是这样的:

import React, { useEffect } from 'react';

从'@alan-ai/alan-sdk-web'导入alanBtn;const alanKey = 我的钥匙;const App = () =>{useEffect(() => {艾伦Btn({钥匙:艾伦钥匙,onCommand: ({ command }) =>{alert('这段代码被执行了');}})}, []);返回 (<div><h1>Alan AI 新闻应用</h1></div>);}导出默认应用程序;

但我收到的错误是:参考错误:未定义导航器..如何解决?

解决方案

这不是你的 Next.js 代码的问题,它只是你应该调用 alan-ai 库的方式.

以下是适合您的解决方案.

import React, { useEffect } from "react";const alanKey = "我的钥匙";功能应用(){useEffect(() => {const alanBtn = require("@alan-ai/alan-sdk-web");艾伦Btn({钥匙:我的钥匙",rootEl: document.getElementById(alan-btn")});}, []);返回 (<div><h1>艾伦人工智能新闻应用</h1>

);}导出默认应用程序;

这里是同一个https的讨论链接://github.com/alan-ai/alan-sdk-web/issues/29#issuecomment-672242925.

希望这能解决您的问题.

快乐编码.

My code is like this:

import React, { useEffect } from 'react';

import alanBtn from '@alan-ai/alan-sdk-web';

const alanKey = my key;
const App = () => {
    useEffect(() => {
        alanBtn({
            key: alanKey,
            onCommand: ({ command }) => {
                    alert('This code was executed');
            }
        })
    }, []);
    return (
        <div><h1>Alan AI News Application</h1></div>);
}
export default App;

But i am getting the error as: Reference Error:Navigator not defined.. How to fix it?

解决方案

This is not an issue with your Next.js code it's just the way you are supposed to call the alan-ai library.

Below is the solution that should work for you.

import React, { useEffect } from "react";

const alanKey = "my key";
function App() {
useEffect(() => {
   const alanBtn = require("@alan-ai/alan-sdk-web");
   alanBtn({
   key: "myKey",
   rootEl: document.getElementById("alan-btn")
  });
}, []);

return (
 <div>
  <h1>Alan AI News Application</h1>
 </div>
 );
}
export default App;

Here is the discussion link for the same https://github.com/alan-ai/alan-sdk-web/issues/29#issuecomment-672242925.

Hope this solves your issue.

Happy Coding.

这篇关于参考错误:未使用 nextjs 定义导航器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆