pmndrs / jotai

👻 Primitive and flexible state management for React
https://jotai.org
MIT License
18.25k stars 590 forks source link

`templateBuilder is not a function` in plugin-react-refresh.mjs #1251

Closed whitetrefoil closed 2 years ago

whitetrefoil commented 2 years ago

When using 'jotai/babel/plugin-react-refresh' w/ vite it throws templateBuilder is not a function at /node_modules/jotai/esm/babel/plugin-react-refresh.mjs.

According to @babel/template #13719, when using native mjs, it requires

import _template from "@babel/template";
const templateBuilder = _template.default;

instead of normal

import templateBuilder from "@babel/template";
dai-shi commented 2 years ago

Yeah, I know this kind of issue is tricky. We have one in zustand: https://github.com/pmndrs/zustand/pull/953

We might need to support both:

import babelTemplate from "@babel/template";
const templateBuilder = babelTemplate.default || babelTemplate;

What do you think? @Thisen

Thisen commented 2 years ago

Yeah, I know this kind of issue is tricky. We have one in zustand: pmndrs/zustand#953

We might need to support both:

import babelTemplate from "@babel/template";
const templateBuilder = babelTemplate.default || babelTemplate;

What do you think? @Thisen

Lets do it. I'll prepare a PR.