繁体   English   中英

./node_modules/mapbox-gl/dist/mapbox-gl.css 模块构建失败:TypeError:无法读取未定义的属性“toFixed”

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

我已经在 React(版本:16.12.0)中集成了 Mapbox GL JS(版本:1.8.0)并且它工作正常。 但是当我尝试运行构建命令时,它会引发以下错误:

./node_modules/mapbox-gl/dist/mapbox-gl.css Module build failed: TypeError: Cannot read property 'toFixed' of undefined at Array.filter (<anonymous>) at Array.filter (<anonymous>) at Array.filter (<anonymous>) at Array.forEach (<anonymous>)

npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! my-app@0.1.0 build: react-scripts build npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the my-app@0.1.0 build script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above. npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! my-app@0.1.0 staging: env-cmd .env.staging npm run build npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the my-app@0.1.0 staging script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

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

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

npm install --save react-scripts@latest

或者

yarn add react-scripts@latest

@Jonas,感谢您的回复。

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

通过从 jsx 页面中移除 mapbox-gl.css 导入并在 index.html 页面中添加以下行

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

谢谢

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM