从React App中获取Mapjs.bundle.js的未型类型错误
在这里的问候,开发人员的支持,
我在 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请参考以下步骤,该步骤告诉我们如何进行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.