在 bit.dev 上安装一个导出的组件时未定义 React

问题描述

我已关注official tutorial of Bit for React。结果在这里https://bit.dev/vibe/react-admin-components/action-buttons

问题是,我无法将上述组件作为 npm 包安装在另一个项目中。使用此导入在运行时(而非构建时)显示 React is undefinedimport ActionButtons from '@bit/vibe.react-admin-components.components';

我相信这是一个快乐的案例,这里没有魔法。当我使用 React 17babel 7 时,也许 babel 是这里的问题。

任何想法都将受到高度赞赏。

解决方法

错误 eval 表示您的 React 默认 Bit 编译器未正确配置以支持新的 JSX 转换器。

修复步骤

  1. fork 默认的 Bit compiler 按照这个 guideline
  2. 按照配置 here 部分更新分叉编译器的 train 以使用自动运行时。 请注意,您必须将编译器的 function QuickApp :fetchTadoData( username,password,client_secret ) self .http = net .HTTPClient( { timeout = 5000 } ) -- 5 seconds local url = "https://auth.tado.com/oauth/token" local requestBody = { action = 'create',params = { ["client_id"] = "tado-web-app",["grant_type"] = "password",["scope"] = "home.user",["username"] = username,["password"] = password,["client_secret"] = client_secret } } local extraheaders = { ["content-type"] = "application/json",["accept"] = "application/json" } self .http :request( url,{ options = { headers = extraheaders,data = json .encode( requestBody ),method = "POST" },success = function( response ) self :debug( response .status ) self :debug( response .data ) end,-- success error = function( msg ) self :debug( 'Error: ' ..msg ) end -- error }) end -- :fetchTadoData() 依赖项升级到 >=7.9.0
  3. 使用新编译器重新构建您的组件
  4. 再次导出该组件并享受
,

我是 Bit 团队的 Josh。
我发布了一个新版本的 React 编译器,现在支持 React 17,请使用新版本并重新导出您的组件。 https://bit.dev/bit/envs/compilers/react?version=1.0.23