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

recoil 返回数组或对象报错 3.4.3 #11429

Closed
skyliwq opened this issue Mar 11, 2022 · 2 comments
Closed

recoil 返回数组或对象报错 3.4.3 #11429

skyliwq opened this issue Mar 11, 2022 · 2 comments

Comments

@skyliwq
Copy link

skyliwq commented Mar 11, 2022

相关平台

微信小程序

复现仓库

https://github.com/skyliwq/taro-recoil-demo.git
小程序基础库: 2.21.1
使用框架: React

复现步骤

const userInfo = selector({
key: 'userInfo',
get: ({ get }) => {

  return {id:34}

}

期望结果

无法打包上线

实际结果

ReferenceError: Window is not defined

环境信息

  Taro CLI 3.4.3 environment info:
    System:
      OS: macOS 12.2.1
      Shell: 3.2.57 - /bin/bash
    Binaries:
      Node: 14.16.1 - /usr/local/bin/node
      npm: 6.14.12 - /usr/local/bin/npm
    npmPackages:
      @tarojs/components: 3.4.3 => 3.4.3 
      @tarojs/mini-runner: 3.4.3 => 3.4.3 
      @tarojs/react: 3.4.3 => 3.4.3 
      @tarojs/runtime: 3.4.3 => 3.4.3 
      @tarojs/taro: 3.4.3 => 3.4.3 
      @tarojs/webpack-runner: 3.4.3 => 3.4.3 
      babel-preset-taro: 3.4.3 => 3.4.3 
      eslint-config-taro: 3.4.3 => 3.4.3 
      react: ^17.0.2 => 17.0.2 

@Chen-jj
Copy link
Contributor

Chen-jj commented Mar 12, 2022

@skyliwq 原因是 Recoil 源码里使用了 Window,而 Taro 在小程序环境没有模拟实现它。

你可以简单地配置一下 definePlugin,定义一个变量 Window 即可:

// config/index.js
config = {
  defineConstants: {
    Window: 'function () {}'
  },
  // ...
}

我们补充一下到文档。

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