Taro编写组件库之后引入到Taro项目中编译错误

1cosmwyk  于 2个月前  发布在  其他
关注(0)|答案(6)|浏览(33)

相关平台

微信小程序

小程序基础库: 2.31.1
使用框架: React

复现步骤

我使用了Taro创建了一个UI组件库发布到私有npm仓库
在一个Taro项目中安装了这个组件库
运行npm run dev:weap会报错React is not defined
但是build不会

期望结果

编译正常

实际结果

编译报错

环境信息

👽 Taro v3.6.5

  Taro CLI 3.6.5 environment info:
    System:
      OS: Windows 10 10.0.22621
    Binaries:
      Node: 16.19.0 - C:\Program Files\nodejs\node.EXE
      Yarn: 1.22.19 - C:\Program Files\nodejs\yarn.CMD
      npm: 8.19.3 - C:\Program Files\nodejs\npm.CMD
    npmPackages:
      @tarojs/cli: 3.6.1 => 3.6.1
      @tarojs/components: 3.6.1 => 3.6.1
      @tarojs/helper: 3.6.1 => 3.6.1
      @tarojs/plugin-framework-react: 3.6.1 => 3.6.1
      @tarojs/plugin-platform-alipay: 3.6.1 => 3.6.1
      @tarojs/plugin-platform-h5: 3.6.1 => 3.6.1
      @tarojs/plugin-platform-jd: 3.6.1 => 3.6.1
      @tarojs/plugin-platform-qq: 3.6.1 => 3.6.1
      @tarojs/plugin-platform-swan: 3.6.1 => 3.6.1
      @tarojs/plugin-platform-tt: 3.6.1 => 3.6.1
      @tarojs/plugin-platform-weapp: 3.6.1 => 3.6.1
      @tarojs/react: 3.6.1 => 3.6.1
      @tarojs/runtime: 3.6.1 => 3.6.1
      @tarojs/shared: 3.6.1 => 3.6.1
      @tarojs/taro: 3.6.1 => 3.6.1
      @tarojs/webpack5-runner: 3.6.1 => 3.6.1
      babel-preset-taro: 3.6.1 => 3.6.1
      eslint-config-taro: 3.6.1 => 3.6.1
      react: ^18.0.0 => 18.2.0
5cg8jx4n

5cg8jx4n2#

查看dev编译后代码发现编写的组件库render方法中直接替换了React字符,而不是使用编译引入的import_react4

sqserrrh

sqserrrh3#

经过查看可能是预编译问题,我们手动关闭预编译后可以正常dev,目前不影响开发,希望官方跟进一下这个问题

pb3s4cty

pb3s4cty4#

麻烦提供一个可复现问题的 demo

acruukt9

acruukt95#

@yclnycl 请问怎么关闭预编译,我也遇到这个报错了。

wvyml7n5

wvyml7n56#

compiler: { type: "webpack5", prebundle: { enable: false, }, },

我关闭了也会报react is not defined

相关问题