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

error: node_modules/@tarojs/rn-supporter/dist/empty-module.js: Cannot use import statement outside a module #12618

Closed
StarlightUnion opened this issue Oct 8, 2022 · 11 comments
Labels
F-react Framework - React T-rn Target - 编译到 React Native V-3 Version - 3.x

Comments

@StarlightUnion
Copy link

StarlightUnion commented Oct 8, 2022

相关平台

React Native

使用框架: React

复现步骤

  • 1 启动yarn dev:rn --qr,启动未报错

  • 2.使用Taro Playground扫码在手机上运行

  • 3.报错:error: node_modules/@tarojs/rn-supporter/dist/empty-module.js: Cannot use import statement outside a module

期望结果

成功在手机上运行

实际结果

报错闪退

环境信息

👽 Taro v3.5.5


  Taro CLI 3.5.5 environment info:
    System:
      OS: macOS 12.6
      Shell: 5.8.1 - /bin/zsh
    Binaries:
      Node: 14.17.6 - ~/.nvm/versions/node/v14.17.6/bin/node
      Yarn: 1.22.4 - /usr/local/bin/yarn
      npm: 6.14.15 - ~/.nvm/versions/node/v14.17.6/bin/npm
    npmPackages:
      @tarojs/cli: 3.5.3 => 3.5.3
      @tarojs/components: 3.5.3 => 3.5.3
      @tarojs/helper: 3.5.3 => 3.5.3
      @tarojs/mini-runner: 3.5.3 => 3.5.3
      @tarojs/plugin-framework-react: 3.5.3 => 3.5.3
      @tarojs/plugin-platform-alipay: 3.5.3 => 3.5.3
      @tarojs/plugin-platform-jd: 3.5.3 => 3.5.3
      @tarojs/plugin-platform-qq: 3.5.3 => 3.5.3
      @tarojs/plugin-platform-swan: 3.5.3 => 3.5.3
      @tarojs/plugin-platform-tt: 3.5.3 => 3.5.3
      @tarojs/plugin-platform-weapp: 3.5.3 => 3.5.3
      @tarojs/react: 3.5.3 => 3.5.3
      @tarojs/rn-runner: 3.5.3 => 3.5.3
      @tarojs/router: 3.5.3 => 3.5.3
      @tarojs/runtime: 3.5.3 => 3.5.3
      @tarojs/shared: 3.5.3 => 3.5.3
      @tarojs/taro: 3.5.3 => 3.5.3
      @tarojs/taro-h5: 3.5.3 => 3.5.3
      @tarojs/taro-rn: 3.5.3 => 3.5.3
      @tarojs/webpack-runner: 3.5.3 => 3.5.3
      babel-preset-taro: 3.5.3 => 3.5.3
      eslint-config-taro: 3.5.3 => 3.5.3
      expo: ~45.0.4 => 45.0.8
      react: ^17.0.2 => 17.0.2
      react-native: ^0.68 => 0.68.3
      taro-ui: ^3.0.0-alpha.9 => 3.0.0-alpha.10
@taro-bot2 taro-bot2 bot added F-react Framework - React T-rn Target - 编译到 React Native V-3 Version - 3.x labels Oct 8, 2022
@StarlightUnion
Copy link
Author

StarlightUnion commented Oct 8, 2022

补充说明Taro Playground版本:IOS 1.7.0

@zhiqingchen
Copy link
Member

Cannot use import statement outside a module

一般为代码写法问题

@StarlightUnion
Copy link
Author

StarlightUnion commented Oct 8, 2022

Cannot use import statement outside a module

一般为代码写法问题

image
是的,是@tarojs/rn-supporter这个包里的empty-module.js这个文件

@StarlightUnion
Copy link
Author

经验证,3.5.6同样存在这个问题,原因为@tarojs/rn-supporter/dist/empty-module.js文件没有声明导出。

@zhiqingchen
Copy link
Member

可以提供下,可复现demo

@StarlightUnion
Copy link
Author

可以提供下,可复现demo

https://github.com/StarlightUnion/demos/tree/main/taro-error-demo

  • 1.yarn install
  • 2.yarn dev:rn --qr
  • 3.使用Taro Playground扫码后app闪退,命令行界面出现错误error: node_modules/@tarojs/rn-supporter/dist/empty-module.js: Cannot use import statement outside a module

@zhiqingchen
Copy link
Member

包含私有包,无法安装成功

@StarlightUnion
Copy link
Author

包含私有包,无法安装成功

稍等,我处理一下

@StarlightUnion
Copy link
Author

包含私有包,无法安装成功

OK了,麻烦重新拉一下

@zhiqingchen
Copy link
Member

zhiqingchen commented Oct 9, 2022

存在几个问题

参考修复 zhiqingchen/taro-test@204a7ba

清除编译缓存重启:yarn dev:rn --qr --reset-cache

  1. 想使用 taro Playground 调试,需要设置 appName: 'taroDemo',
  2. config/index.js 不支持 import 语法
  3. taro ui 支持 rn 在 beta 版本 Taro UI 支持 React native 内测版本 taro-ui#1424
  4. react 18,在 rn 0.69 及 taro 3.5.6 才被支持。
  5. iconfont 没有内置支持。
  6. 部分css语法在rn并不是生效。https://docs.taro.zone/docs/react-native-remind

@StarlightUnion
Copy link
Author

存在几个问题

参考修复 zhiqingchen/taro-test@204a7ba
清除编译缓存重启:yarn dev:rn --qr --reset-cache

  1. 想使用 taro Playground 调试,需要设置 appName: 'taroDemo',
  2. config/index.js 不支持 import 语法
  3. taro ui 支持 rn 在 beta 版本 Taro UI 支持 React native 内测版本 taro-ui#1424
  4. react 18,在 rn 0.69 及 taro 3.5.6 才被支持。
  5. iconfont 没有内置支持。
  6. 部分css语法在rn并不是生效。https://docs.taro.zone/docs/react-native-remind

感谢,这就试试👍👍👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F-react Framework - React T-rn Target - 编译到 React Native V-3 Version - 3.x
Projects
None yet
Development

No branches or pull requests

2 participants