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

不支持typescript 没有@types吗? #120

Open
Faithree opened this issue Aug 28, 2018 · 4 comments
Open

不支持typescript 没有@types吗? #120

Faithree opened this issue Aug 28, 2018 · 4 comments

Comments

@Faithree
Copy link

No description provided.

@Faithree
Copy link
Author

image

@Lobos
Copy link
Owner

Lobos commented Aug 29, 2018

嗯,没有加 .d.ts 文件,暂不支持 TypeScript

@Faithree
Copy link
Author

还有一个问题。
我现在自己写d.tsx文件,例如我给Button.js 写了一个Button.d.ts
并且使用它
import Button from 'rctui/Button';
但是他会报错
./node_modules/rctui/Button.js
Module build failed (from ./node_modules/babel-loader/lib/index.js):
SyntaxError: D:\demo\environment\node_modules\rctui\Button.js: Unexpected token (32:11)
我的babel配置如下

"@babel/core": "^7.0.0",
"@babel/plugin-transform-runtime": "^7.0.0",
"@babel/polyfill": "^7.0.0",
"@babel/preset-env": "^7.0.0",
"@babel/preset-react": "^7.0.0",
"@babel/preset-typescript": "^7.0.0",
"@babel/runtime": "^7.0.0",

 {
        test: /\.(js|jsx|ts|tsx)$/,
        use: 'babel-loader'
      },

.babelrc

{
  "presets": [
    "@babel/preset-react",
    [
      "@babel/preset-env",
      {
        "modules": false,
        "targets": {
          "browsers": ["last 5 versions"]
        },
        "useBuiltIns": "usage"
      }
    ],
    "@babel/preset-typescript"
  ],
  "plugins": [
    [
      "@babel/transform-runtime",
      {
        "helpers": false,
        "regenerator": true
      }
    ]
  ]
} 

奇怪的是,我把button.js从node_modules文件放到src目录下,则不会报错,
后来经过测试放到node_modules/rctui里面的Button.js render函数内解析不了jsx,返回123456数字或者字符串则不会报错。

render() {
   123456
  }

因为用了babel7 目前找不到问题出在哪,感觉是babel7的问题

@Faithree
Copy link
Author

因为看源码,rctui的按需加载是直接引用Button的,放到src目录下跟node_modules下是一样的。
我把错误复现放到了我的仓库上,如果作者有空的话,麻烦看一下,webpack4+babel7+tsx的一个环境。
在这里我说明一下,babel7支持typescript不再需要ts-loader
通过presets 的形式 "@babel/preset-typescript"
地址:https://github.com/Faithree/webpack-ci/tree/master/25-rctui

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

2 participants