从React App中获取Mapjs.bundle.js的未型类型错误

发布于 2025-01-22 17:57:14 字数 2250 浏览 1 评论 0 原文

在这里的问候,开发人员的支持,

我在 mapjs.s.bundle.js 的浏览器控制台中看到了许多 untured typeerrors ,当我与React应用中的地图进行交互时。

我已经使用下面的最小应用复制了错误。任何洞察力都非常感谢。

package.json:

{
    "type": "module",
    "scripts": {
        "start": "parcel index.html --open"
    },
    "devDependencies": {
        "parcel": "^2.4.1"
    },
    "dependencies": {
        "@here/maps-api-for-javascript": "^1.30.14",
        "react": "^18.0.0",
        "react-dom": "^18.0.0"
    }
}

index.html:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Map App</title>
</head>
<body>
    <div id="root" />
    <script src="index.jsx" type="module"></script>
</body>
</html>

index.jsx:

import React from 'react';

import { createRoot } from 'react-dom/client';

import Map from './Map';

const rootElem = document.getElementById("root");

createRoot(rootElem).render(<Map />);

map.jsx :(从develper.here.here.here.com上复制的react教程)

import React from 'react';
import H from "@here/maps-api-for-javascript";

export default class Map extends React.Component {
  constructor(props) {
    super(props);
    // the reference to the container
    this.ref = React.createRef();
    // reference to the map
    this.map = null;
  }

  componentDidMount() {
    if (!this.map) {
      // instantiate a platform, default layers and a map as usual
      const platform = new H.service.Platform({
        apikey: MyApiKey
      });
      const layers = platform.createDefaultLayers();
      const map = new H.Map(
        this.ref.current,
        layers.vector.normal.map,
        {
          pixelRatio: window.devicePixelRatio,
          center: {lat: 0, lng: 0},
          zoom: 2,
        },
      );
      this.map = map;
    }
  }

  render() {
    return (
      <div
        style={{ width: '300px', height:'300px' }}
        ref={this.ref}
      />
    )
  }
}

然后运行:

npm install && npm start

Greetings HERE Developer Support,

I'm seeing numerous Uncaught TypeErrors in the browser console coming from mapjs.bundle.js as I interact with the map in my React app.

I've reproduced the error with the minimal app below. Any insight is much appreciated.

package.json:

{
    "type": "module",
    "scripts": {
        "start": "parcel index.html --open"
    },
    "devDependencies": {
        "parcel": "^2.4.1"
    },
    "dependencies": {
        "@here/maps-api-for-javascript": "^1.30.14",
        "react": "^18.0.0",
        "react-dom": "^18.0.0"
    }
}

index.html:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Map App</title>
</head>
<body>
    <div id="root" />
    <script src="index.jsx" type="module"></script>
</body>
</html>

index.jsx:

import React from 'react';

import { createRoot } from 'react-dom/client';

import Map from './Map';

const rootElem = document.getElementById("root");

createRoot(rootElem).render(<Map />);

Map.jsx: (copied from the React tutorial at developer.here.com)

import React from 'react';
import H from "@here/maps-api-for-javascript";

export default class Map extends React.Component {
  constructor(props) {
    super(props);
    // the reference to the container
    this.ref = React.createRef();
    // reference to the map
    this.map = null;
  }

  componentDidMount() {
    if (!this.map) {
      // instantiate a platform, default layers and a map as usual
      const platform = new H.service.Platform({
        apikey: MyApiKey
      });
      const layers = platform.createDefaultLayers();
      const map = new H.Map(
        this.ref.current,
        layers.vector.normal.map,
        {
          pixelRatio: window.devicePixelRatio,
          center: {lat: 0, lng: 0},
          zoom: 2,
        },
      );
      this.map = map;
    }
  }

  render() {
    return (
      <div
        style={{ width: '300px', height:'300px' }}
        ref={this.ref}
      />
    )
  }
}

Then run:

npm install && npm start

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

九公里浅绿 2025-01-29 17:57:14

请参考以下步骤,该步骤告诉我们如何进行React设置。

设置
对于新的React应用程序的快速设置,我们将使用创建react react app app 环境。它提供了一种快速开始构建新的单页应用程序的方法。如下所示执行NPX Runner(它需要节​​点&gt; = 8.10和NPM&gt; = 5.6):

NPX create-react-app-app jsapi-react&amp; CD JSAPI-REACT

您可以检查页面相同。

Please refer below steps, which tell how we can do the react setup.

Setup
For the fast setup of the new React application we will use the Create React App environment. It provides a fast way to get started building a new single-page application. Execute the npx runner as below (it requires Node >= 8.10 and npm >= 5.6):

npx create-react-app jsapi-react && cd jsapi-react

You can check the React setup page for the same.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文