question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Discussion about main field of antd-mobile

See original GitHub issue

https://github.com/ant-design/ant-design-mobile/issues/66 https://github.com/ant-design/ant-design-mobile/issues/523


社区遇到巨量 import { Xxx } from 'antd-mobile' 找不到模块(找不到 antd-mobile 或 react-native)的问题,根本原因是由于 antd-mobile 同时用于 web 和 native 两种使用场景,以不同的后缀 *.web.js 和 *.js 作为区分,所以项目没有设置统一的入口文件,需要直接引用模块文件。

没有 main 文件也会导致 eslint 报 import/no-unresolved 规则的错误。

目前主要解决方案如下:

  1. 找不到 antd-mobile:接入 babel-plugin-import,解决没有 main 入口文件的问题。

    或者不再推荐 import { Button } from 'antd-mobile'; 的写法,直接 import Button from 'antd-mobile/lib/button';

  2. 找不到 react-native:增加 [resolve.extention] 配置(https://github.com/ant-tool/atool-build/blob/e4bd2959689b6a95cb5c1c854a5db8c98676bdb3/src/getWebpackCommonConfig.js#L78),解决 web 和 native 模块路由的问题。

上面两个方案比较影响易用性,很多用户搞不定这个。


建议:

antd-mobile antd-mobile-native 分开,npm run pub 时同时发布两个包,这样两个包可以各自指定 main 入口,而且不再需要配置 resolve.extention。

相关讨论:https://github.com/ant-design/ant-design-mobile/commit/f561b6eb4f577eea502065df93166a88d443e4d9#commitcomment-20043061

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:7
  • Comments:32 (17 by maintainers)

github_iconTop GitHub Comments

10reactions
johnbiancommented, Mar 15, 2017

image 但是我的 babel-plugin-import 已经install过了。。package里面也有了。。 这个是什么原因呢。。 .babelrc文件配置 { “presets”: [“react-native”], “plugins”: [[“import”, { “libraryName”: “antd-mobile” }]] }

4reactions
yyh1102commented, Apr 23, 2017

最新的antd-mobile版本,按官方文档配置babel-plugin-import 仍然报无法找到"antd-mobile"。我的RN版本是0.43

Read more comments on GitHub >

github_iconTop Results From Across the Web

FAQ - Ant Design
Here are the frequently asked questions about Ant Design and antd that you should look up before you ask in the community or...
Read more >
Layout - Ant Design
This pattern demonstrates efficiency in the main workarea, while using some vertical space. And because the horizontal space of the navigation is limited,...
Read more >
Grid - Ant Design
In the grid system, we define the frame outside the information area based on row and column , to ensure that every area...
Read more >
Input - Ant Design
A basic widget for getting the user input is a text field. Keyboard and mouse can be used for providing or changing data....
Read more >
Customize Theme - Ant Design
Ant Design allows you to customize our design tokens to satisfy UI diversity from business or brand requirements, including primary color, border radius, ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found