pmndrs / valtio

🧙 Valtio makes proxy-state simple for React and Vanilla
https://valtio.dev
MIT License
9.16k stars 257 forks source link

Possible regression on 0.8.1 #110

Closed tommywalkie closed 3 years ago

tommywalkie commented 3 years ago

Tried using the newly released 0.8.1 version (via ES Modules) today and couldn't import any of Valtio methods.

JSFiddle

// 0.8.0
import { subscribe as subscribeA } from 'https://cdn.skypack.dev/valtio@0.8.0'
// 0.8.1
import { subscribe as subscribeB } from 'https://cdn.skypack.dev/valtio@0.8.1'

console.log(subscribeA) // ✔️ works
console.log(subscribeB) // ❌ SyntaxError: import not found: subscribe
dai-shi commented 3 years ago

Thanks for reporting! Sorry for the inconvenience. Okay, I need to look for some other solutions that work with esm too. 🤔

dai-shi commented 3 years ago
import { subscribe as subscribeB } from 'https://cdn.skypack.dev/valtio@0.8.1/vanilla'

This seems to work. just FYI.


https://github.com/pmndrs/valtio/blob/a396bfdfde33a1ce93c1e9c24e387b068df3d50e/src/index.ts#L1

This doesn't seem to work with pika? snowpack?

tommywalkie commented 3 years ago

@dai-shi That's possible. Looking at https://github.com/snowpackjs/snowpack/issues/2774, the zarr package seems to run with similar issues.

dai-shi commented 3 years ago

It turns out #112 didn't fix this issue at all. https://jsfiddle.net/gpLesnzu/

Does anyone know how to work around this?

lauritzsh commented 3 years ago

I wanted to try this library since it seems simple and flexible, while allowing writing to state outside React compared to Jotai. However, using Snowpack for development, I have a problem importing just following the examples posted. With

import { proxy } from 'valtio';

export const test = proxy({ hello: 'world' });

I get Uncaught SyntaxError: The requested module '../../../../_snowpack/pkg/valtio.js' does not provide an export named 'proxy'. Some workarounds seems to be import { proxy } from 'valtio/vanilla' but that results in Uncaught Error: Please use proxy object. The only thing working for me is

import v from 'valtio';

export const test = v.proxy({ hello: 'world' });

If I do import * as v from 'valtio'; then the structure is

image

if that helps.

Just curious if it's related to this issue?

dai-shi commented 3 years ago

Oh, no. We would definitely like to fix the issue with snowpack. The issue seems related to this one, but not 100% as the workaround is different. I will investigate it when I have a chance to learn snowpack, but if someone can help on this, it'd be very appreciated.

lxsmnsyc commented 3 years ago
Screen Shot 2021-07-09 at 10 35 15 PM

@dai-shi This should be fixed now in 1.0.7 (logged module object is from Skypack, Valtio 1.0.7)

import * as valtio from 'https://cdn.skypack.dev/valtio';

console.log(valtio);
dai-shi commented 3 years ago

Cool. Thanks for confirming.