[英]Error using react-map-gl in create-react-app
Building a simple app to tryout Uber's React Map GL using the super simple Create React App setup. 使用超简单的创建React App设置构建一个简单的应用程序来试用Uber的React Map GL 。 Here's a simplified setup of what I have:
这是我所拥有的简化设置:
import React, { Component } from 'react'
import MapGL from 'react-map-gl'
class Home extends Component {
render() {
return (
<MapGL
width={400}
height={400}
latitude={37.7577}
longitude={-122.4376}
zoom={8}
mapStyle="mapbox://styles/mapbox/dark-v9"
/>
}
}
which results in an error of: 这将导致以下错误:
Uncaught TypeError: Cannot convert undefined or null to object
at Function.keys (<anonymous>)
at new module.exports (index.js:9)
at Object.<anonymous> (web_worker.js:5)
at __webpack_require__ (bootstrap e5da5fb…:555)
at fn (bootstrap e5da5fb…:86)
at Object.<anonymous> (worker_pool.js:4)
at __webpack_require__ (bootstrap e5da5fb…:555)
at fn (bootstrap e5da5fb…:86)
at Object.<anonymous> (global_worker_pool.js:2)
at __webpack_require__ (bootstrap e5da5fb…:555)
In looking at Uber's example app using webpack I noticed they're using the transform-loader?brfs-babel
loader for the mapbox-gl.js
file. 在使用webpack查看Uber的示例应用程序时,我注意到他们正在对
mapbox-gl.js
文件使用transform-loader?brfs-babel
loader。
With Create React App you don't have access to the webpack configuration since it's contained within another package, so the only option seems to be to run npm run eject
to pull the dependancies and webpack configuration into the project. 使用Create React App时,您无权访问webpack配置,因为它包含在另一个软件包中,因此唯一的选择似乎是运行
npm run eject
exit将依赖关系和webpack配置拉入项目。
Is ejecting the only option? 是弹出的唯一选择吗? Or am I missing a way to do this within a standard
create-react-app
install? 还是我错过了在标准
create-react-app
安装中执行此操作的方法?
For development add mapboxApiAccessToken property. 为了进行开发,请添加mapboxApiAccessToken属性。
If you're usin CRA, In production in .env file set REACT_APP_MAPBOX_ACCESS_TOKEN environmen varilable. 如果您使用的是CRA,请在.env文件的生产环境中设置REACT_APP_MAPBOX_ACCESS_TOKEN环境可变。 mapboxApiAccessToken={'process.env.REACT_APP_MAPBOX_ACCESS_TOKEN'}/>
mapboxApiAccessToken = {'process.env.REACT_APP_MAPBOX_ACCESS_TOKEN'} />
<MapGL
width={400}
height={400}
latitude={37.7577}
longitude={-122.4376}
zoom={8}
mapStyle="mapbox://styles/mapbox/dark-v9"
mapboxApiAccessToken={'your-access-toekn-goes-here'}/>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.