./node_modules/mapbox-gl/dist/mapbox-gl.css Module build failed: TypeError: Cannot read property 'toFixed' of undefined

./node_modules/mapbox-gl/dist/mapbox-gl.css Module build failed: TypeError: Cannot read property 'toFixed' of undefined

我已将 Mapbox GL JS(版本:1.8.0)集成到 React(版本:16.12.0)中,并且运行良好。但是当我尝试 运行 构建命令时,它会抛出以下错误:

./node_modules/mapbox-gl/dist/mapbox-gl.css 模块构建失败:类型错误:无法读取未定义的 属性 'toFixed' <code>at Array.filter (<anonymous>) at Array.filter (<anonymous>) at Array.filter (<anonymous>) at Array.forEach (<anonymous>)

npm 错误!代码生命周期 错误!错误号 1 错误!我的应用程序@0.1.0 构建:react-scripts build 错误!退出状态 1 错误! 错误! my-app@0.1.0 构建脚本失败。 错误!这可能不是 npm 的问题。上面可能有额外的日志输出。 错误!代码生命周期 错误!错误号 1 错误! my-app@0.1.0 分期:env-cmd .env.staging npm run build 错误!退出状态 1 错误! 错误! my-app@0.1.0 暂存脚本失败。 错误!这可能不是 npm 的问题。上面可能有额外的日志输出。

谁能告诉我为什么 react build 命令抛出错误而 npm start 命令却没有?

我在使用 react-scripts@1.1.0 构建时遇到了同样的问题。我升级到最新版本 (v3.4.0),为我解决了这个问题。

npm install --save react-scripts@latest

yarn add react-scripts@latest

@Jonas,感谢您的回复。

我已经通过以下两个步骤修复了它:

通过删除 mapbox-gl.css 从 jsx 页面导入 并在 index.html 页面

添加以下行
<link href="https://api.tiles.mapbox.com/mapbox-gl-js/v1.8.0/mapbox-gl.css" rel="stylesheet" />

谢谢