Ant-design-mobile: 找不到antd-mobile模块

Created on 16 Aug 2016  ·  4Comments  ·  Source: ant-design/ant-design-mobile

本地环境

  • antd-mobile 版本:0.7.7
  • 操作系统及其版本:mac os 10.11.6
  • 浏览器及其版本:chrome 52.0.2743.116 (64-bit)

你做了什么?

我的项目因为需要同时支持移动端和pc页面,所以同时引入了antd和antd-mobile。antd一切正常,但是antd-mobile有问题:
比如引入 antd-mobile 的 Button
import { Button} from 'antd-mobile'
以及
import Button from 'antd-mobile/lib/button'
两种方式均进行了尝试。
在第一种方式的情况下也尝试了使用babel-plugin-antd插件:
"plugins": [["antd", {
"style": true,
"libraryName": "antd"
}],["antd", {
"style": true,
"libraryName": "antd-mobile"
}]]

你期待的结果是:

像官网一样正常显示

实际上的结果:

如果采用import { Button} from 'antd-mobile'的方式,则出现找不到antd-mobile模块的异常:
./src/containers/mobile/public/Nav.js
Module not found: Error: Cannot resolve module 'antd-mobile' in /Users/dongchao/wk/marketing/src/containers/mobile/public
resolve module antd-mobile in /Users/dongchao/wk/marketing/src/containers/mobile/public
looking for modules in /Users/dongchao/wk/marketing/node_modules
resolve 'file' antd-mobile in /Users/dongchao/wk/marketing/node_modules
resolve file
/Users/dongchao/wk/marketing/node_modules/antd-mobile is not a file
/Users/dongchao/wk/marketing/node_modules/antd-mobile.js doesn't exist
/Users/dongchao/wk/marketing/node_modules/antd-mobile.jsx doesn't exist
resolve 'file' or 'directory' /Users/dongchao/wk/marketing/node_modules/antd-mobile
resolve file
/Users/dongchao/wk/marketing/node_modules/antd-mobile is not a file
/Users/dongchao/wk/marketing/node_modules/antd-mobile.js doesn't exist
/Users/dongchao/wk/marketing/node_modules/antd-mobile.jsx doesn't exist
resolve directory
directory default file index
resolve file index in /Users/dongchao/wk/marketing/node_modules/antd-mobile
/Users/dongchao/wk/marketing/node_modules/antd-mobile/index doesn't exist
/Users/dongchao/wk/marketing/node_modules/antd-mobile/index.js doesn't exist
/Users/dongchao/wk/marketing/node_modules/antd-mobile/index.jsx doesn't exist
resolve 'bower component' antd-mobile manifest files using [bower.json]
resolve file
/Users/dongchao/wk/marketing/src/containers/mobile/public/bower_components/antd-mobile/bower.json doesn't exists
/Users/dongchao/wk/marketing/src/containers/mobile/bower_components/antd-mobile/bower.json doesn't exists
/Users/dongchao/wk/marketing/src/containers/bower_components/antd-mobile/bower.json doesn't exists
/Users/dongchao/wk/marketing/src/bower_components/antd-mobile/bower.json doesn't exists
/Users/dongchao/wk/marketing/bower_components/antd-mobile/bower.json doesn't exists
/Users/dongchao/wk/bower_components/antd-mobile/bower.json doesn't exists
/Users/dongchao/bower_components/antd-mobile/bower.json doesn't exists
/Users/bower_components/antd-mobile/bower.json doesn't exists
/bower_components/antd-mobile/bower.json doesn't exists
[/Users/dongchao/wk/marketing/node_modules/antd-mobile.js]
[/Users/dongchao/wk/marketing/node_modules/antd-mobile.js]
[/Users/dongchao/wk/marketing/node_modules/antd-mobile.jsx]
[/Users/dongchao/wk/marketing/node_modules/antd-mobile.jsx]
[/Users/dongchao/wk/marketing/node_modules/antd-mobile/index]
[/Users/dongchao/wk/marketing/node_modules/antd-mobile/index.js]
[/Users/dongchao/wk/marketing/node_modules/antd-mobile/index.jsx]
@ ./src/containers/mobile/public/Nav.js 19:18-40

若采用import Button from 'antd-mobile/lib/button',错误则是找不到react-native:
ERROR in ./~/antd-mobile/lib/button/index.js
Module not found: Error: Cannot resolve module 'react-native' in /Users/dongchao/wk/marketing/node_modules/antd-mobile/lib/button

Most helpful comment

好大的坑, 查阅了相关问题,都是提到语法问题,下载官方示例跑通后,配置 antd和antd-mobile 共存,结果一样报错,最终发现是 babel-plugin-antd 版本不对,默认安装的是0.4.1 , 共存问题在0.5.1才被支持,升级后解决问题 ,请大家参考 少走弯路
npm install [email protected]

All 4 comments

写法错误,看这里 https://github.com/ant-design/babel-plugin-antd 文档
类似这样

["antd", [
  { "style": "css", "libraryName": "antd" },
  { "style": "css", "libraryName": "antd-mobile" }
]]

关键问题应该是我没看readme里面webpack需要配置的东西。建议把这个配置的说明也放到文档的安装和使用说明里。

好大的坑, 查阅了相关问题,都是提到语法问题,下载官方示例跑通后,配置 antd和antd-mobile 共存,结果一样报错,最终发现是 babel-plugin-antd 版本不对,默认安装的是0.4.1 , 共存问题在0.5.1才被支持,升级后解决问题 ,请大家参考 少走弯路
npm install [email protected]

This thread has been automatically locked because it has not had recent activity. Please open a new issue for related bugs and link to relevant comments in this thread.

Was this page helpful?
0 / 5 - 0 ratings