我在使用react-map-gl库时遇到模块解析器错误

发布于 2025-01-10 09:08:39 字数 470 浏览 0 评论 0原文

    ./node_modules/react-map-gl/dist/esm/components/use-control.js 12:46    
Module parse failed: Unexpected token (12:46)
File was processed with these loaders:
* ./node_modules/babel-loader/lib/index.js
You may need an additional loader to handle the result of these loaders.
|
|     if (!map.hasControl(ctrl)) {
>       map.addControl(ctrl, (opts || onRemove)?.position);
|     }
|

我正在尝试使用 Mapbox 进行地图集成,但在运行代码时遇到上述错误,有人知道这个问题吗?请帮助我

    ./node_modules/react-map-gl/dist/esm/components/use-control.js 12:46    
Module parse failed: Unexpected token (12:46)
File was processed with these loaders:
* ./node_modules/babel-loader/lib/index.js
You may need an additional loader to handle the result of these loaders.
|
|     if (!map.hasControl(ctrl)) {
>       map.addControl(ctrl, (opts || onRemove)?.position);
|     }
|

I am trying to use Mapbox for Map integration but I am getting above error while running the code, is anybody aware of this issue please help me

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

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

发布评论

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

评论(2

悸初 2025-01-17 09:08:39

我遇到了同样的问题。对我来说,将反应脚本从 ^4.0.3 升级到 ^5.0.0

"react-scripts": "^5.0.0"

I ran into this same exact problem. What did it for me was upgrading react-scripts from ^4.0.3 to ^5.0.0

"react-scripts": "^5.0.0"

你是暖光i 2025-01-17 09:08:39

您需要转译react-map-gl lib。

同样的方法,https://moti.fyi/web
该解决方案也可用于@gorhom/bottom-sheet。

试试这个。

webpack.config.js

const createExpoWebpackConfigAsync = require("@expo/webpack-config");

module.exports = async function (env, argv) {

  const config = await createExpoWebpackConfigAsync(
    {
      ...env,
      babel: {
        dangerouslyAddModulePathsToTranspile: ["react-map-gl",], // this line!
      },
    },
    argv
    );

  // Customize the config before returning it.
  return config;
};

同样的问题。
React 模块解析失败 – react-map-gl

You need to transpile react-map-gl lib.

Same approach, https://moti.fyi/web
This solution can be used for @gorhom/bottom-sheet also.

Try this.

webpack.config.js

const createExpoWebpackConfigAsync = require("@expo/webpack-config");

module.exports = async function (env, argv) {

  const config = await createExpoWebpackConfigAsync(
    {
      ...env,
      babel: {
        dangerouslyAddModulePathsToTranspile: ["react-map-gl",], // this line!
      },
    },
    argv
    );

  // Customize the config before returning it.
  return config;
};

Same question.
React Module Parse Failed – react-map-gl

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