Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

antd-mobile 用typescript+webpack打包时提示找不到react-native definition file. #636

Closed
mineralres opened this issue Dec 14, 2016 · 23 comments

Comments

@mineralres
Copy link

mineralres commented Dec 14, 2016

本地环境

  • antd-mobile 版本:0.9.11
  • 浏览器 (或标明是 react-native) 及其版本:chome
  • 运行环境及其版本:

你做了什么?

我做的web项目.

import { Button } from 'antd-mobile';

用webpack+typescript+antd-mobile打包

提示
Cannot find type definition file for 'react-native'.

我想可能是因为antd-mobile的web.d.ts文件不能优先被tsc处理

@mineralres
Copy link
Author

ERROR in ./src/index.tsx
Module not found: Error: Cannot resolve module 'antd-mobile' i n C:\develop\typescript\hello\src
@ ./src/index.tsx 5:20-42

ERROR in [at-loader] node_modules\antd-mobile\lib\search-bar\P ropsType.d.ts:2:1
Cannot find type definition file for 'react-native'.

ERROR in [at-loader] node_modules\antd-mobile\lib\search-bar\P ropsType.d.ts:38:22
Namespace 'React' has no exported member 'ViewStyle'.

ERROR in [at-loader] node_modules\antd-mobile\lib\search-bar\P ropsType.d.ts:39:24

@mineralres mineralres changed the title antd-mobile 用typescript编译时怎么设置优先找*.web.d.ts? antd-mobile 用typescript+webpack打包时提示找不到react-native definition file. Dec 14, 2016
@mineralres
Copy link
Author

webpack.config.js配置
module.exports = {
entry: "./src/index.tsx",
output: {
filename: "bundle.js",
path: __dirname + "/dist"
},

// Enable sourcemaps for debugging webpack's output.
devtool: "source-map",

resolve: {
    // Add '.ts' and '.tsx' as resolvable extensions.
    extensions: ["", ".webpack.js", ".web.js", ".ts", ".tsx", ".js"]
},

module: {
    loaders: [
        // All files with a '.ts' or '.tsx' extension will be handled by 'awesome-typescript-loader'.
        { test: /\.tsx?$/, loader: "awesome-typescript-loader" }
    ],

    preLoaders: [
        // All output '.js' files will have any sourcemaps re-processed by 'source-map-loader'.
        { test: /\.js$/, loader: "source-map-loader" }
    ]
},

// When importing a module whose path matches one of the following, just
// assume a corresponding global variable exists and use that instead.
// This is important because it allows us to avoid bundling all of our
// dependencies, which allows browsers to cache those libraries between builds.
externals: {
    "react": "React",
    "react-dom": "ReactDOM"
},

};

@warmhug
Copy link
Contributor

warmhug commented Dec 14, 2016

关联 #531 #376

@mineralres
Copy link
Author

请问有没有在typescript中使用 antd-mobile的实例, 我在文档里没有找到

@mineralres
Copy link
Author

我看了 https://github.com/warmhug/__/tree/master/_react/dva-ts, 这里没有关于怎么引用antd-mobile的例子。
antd-mobile不是一个组件库吗? 我直接npm install antd-mobile; 之后, 在代码里
import {Button} from 'antd-mobile';
然后用webpack+ts-loader 打包就遇到错误提示,我是根据typescript官方文档上的提示做的https://www.typescriptlang.org/docs/handbook/react-&-webpack.html

编译提示:

ERROR in [at-loader] node_modules\antd-mobile\lib\search-bar\PropsType.d.ts:2:1
Cannot find type definition file for 'react-native'.

ERROR in [at-loader] node_modules\antd-mobile\lib\search-bar\PropsType.d.ts:38:22
Namespace 'React' has no exported member 'ViewStyle'.

ERROR in [at-loader] node_modules\antd-mobile\lib\search-bar\PropsType.d.ts:39:24
Namespace 'React' has no exported member 'ViewStyle'.

ERROR in [at-loader] node_modules\antd-mobile\lib\search-bar\PropsType.d.ts:40:36
Namespace 'React' has no exported member 'ViewStyle'.

ERROR in [at-loader] node_modules\antd-mobile\lib\search-bar\PropsType.d.ts:41:27
Namespace 'React' has no exported member 'ViewStyle'.

@warmhug
Copy link
Contributor

warmhug commented Dec 14, 2016

@mineralres 这个估计是 search-bar 组件里引用错误,我修复下

warmhug added a commit that referenced this issue Dec 14, 2016
@mineralres
Copy link
Author

这个fix什么时候会更新到npm 包中呢? 我现在通过什么方式应用你这个fix最合适?

@xesrevinu
Copy link

配置了一个测试项目inferno-starter,使用typescript引入antd-mobile就报错😔

@warmhug
Copy link
Contributor

warmhug commented Dec 15, 2016

@mineralres @xiaokekeT 下午发 0.9.12 ,会解决这个问题。并提供一个推荐的 typescript 项目示例出来

@warmhug
Copy link
Contributor

warmhug commented Dec 15, 2016

已发布 0.9.12 ,外带推荐的 typescript 使用示例:
image
关联 #56 (comment)

@mineralres
Copy link
Author

@warmhug 例子跑通了。
用typescript ,还是需要用到babel-loader吗? 比如import{Button} from 'antd-mobile'; 编译出来的文件转换为'/antd-mobile/lib/button/'吗?

@warmhug
Copy link
Contributor

warmhug commented Dec 15, 2016

需要,babel-plugin-import 需要 babel

@mineralres
Copy link
Author

mineralres commented Dec 15, 2016

TabBarItem 这种需要怎么引入呢? 我直接import{TabBar, TabBarItem} from 'antd-mobile';是找不到的模块,于是我尝试在tab-bar/index.web.d.ts加一句export { default as TabBarItem } from './TabBarItem';
又会提示找不到
Cannot resolve module 'antd-mobile/lib/tab-bar-item/style/css'

@warmhug
Copy link
Contributor

warmhug commented Dec 16, 2016

const TabBarItem = TabBar.Item

@mineralres
Copy link
Author

添加const TabBarItem = TabBar.Item之后
ERROR in ./src/components/TsExample.tsx
(5,27): error TS2339: Property 'Item' does not exist on type 'ClassicComponentClass<{ prefixCls: string; barTintColor: string; tintColor: string; unselectedTin...'.

ERROR in ./src/components/TsExample.tsx
Module not found: Error: Cannot resolve module 'antd-mobile' in C:\develop\typescript\hello\src\components
@ ./src/components/TsExample.tsx 19:20-42

@afc163
Copy link
Member

afc163 commented Dec 16, 2016

#602

@xesrevinu
Copy link

proptypes漏太多了没法用啊

@warmhug
Copy link
Contributor

warmhug commented Dec 19, 2016

@xiaokekeT @mineralres 哪些 proptypes 漏了,欢迎帮忙贴出来、下个版本会全部 review 一遍尽量都修复掉

@benjycui
Copy link
Contributor

propTypes@yiminghe 之前有意删除的。

@warmhug
Copy link
Contributor

warmhug commented Dec 20, 2016

@benjycui 我知道这个,这里是说的 typescript 里的 interface 不完善

This was referenced Dec 20, 2016
@warmhug
Copy link
Contributor

warmhug commented Dec 23, 2016

有问题在新开 issue ,前边提到的问题都修复了,升级到新版本

@warmhug warmhug closed this as completed Dec 23, 2016
@paranoidjk
Copy link
Contributor

@benjycui

删除propTypes, 完全依赖ts的类型检查可以理解。
但是我有个疑问,用户使用的时候(假设用户代码是非typescript),运行时组件内部不是就没有React PropType的检查了吗?
还是我哪里理解错了?

@benjycui
Copy link
Contributor

是的, @yiminghe 决定的。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants