Coder Social home page Coder Social logo

Comments (4)

Faithree avatar Faithree commented on August 16, 2024

image

from react-ui.

Lobos avatar Lobos commented on August 16, 2024

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

from react-ui.

Faithree avatar Faithree commented on August 16, 2024

还有一个问题。
我现在自己写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的问题

from react-ui.

Faithree avatar Faithree commented on August 16, 2024

因为看源码,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

from react-ui.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.