Hydration error: import_url.fileURLToPath is not a function
- Dominant language
- TypeScript
- Stars
- 15.9k
- Forks
- 1.6k
- Avg merge
- 3d 9m
- Merged PRs (30d)
- 59
Description
### Provide a general summary of the issue here
When using the `styles` macro in S2, I get this error: `import_url.fileURLToPath is not a function`
### 🤔 Expected Behavior?
The error should not be there
### 😯 Current Behavior
The `style` macro works correctly on node, but doesn't work on the client, because of a hydration error.
It's caused by importing modules such as `fs`, `path`, `url`, etc... which aren't available on the browser. Here's the trace:
```
TypeError: import_url.fileURLToPath is not a function
http://localhost:3000/node_modules/.vite/deps/@react-spectrum_s2_style.js?v=6db6415d:53
```
### 💁 Possible Solution
The issue seems to be here:
https://github.com/adobe/react-spectrum/blob/daafdd59d974442351d237baeb9a1598c2b2cb85/packages/%40react-spectrum/s2/style/style-macro.ts#L18
Where you import the JSON file manually using fs, etc... instead of importing the `package.json` normally, as done for `properties.json` done just 2 lines above.
### 🔦 Context
_No response_
### 🖥️ Steps to Reproduce
Just install and use react spectrum in vite
### Version
1.1.0
### What browsers are you seeing the problem on?
Firefox
### If other, please specify.
_No response_
### What operating system are you using?
Linux
### 🧢 Your Company/Team
_No response_
### 🕷 Tracking Issue
_No response_
Contributor guide
Assessment
This issue has not been assessed yet.