[V2] UNISTYLES_ERROR_RUNTIME_UNAVAILABLE
atanaskanchev opened this issue · comments
Description
Getting error UNISTYLES_ERROR_RUNTIME_UNAVAILABLE
coming from node_modules/react-native-unistyles/src/Unistyles.ts:18
if (!isInstalled) {
throw new Error(UnistylesError.RuntimeUnavailable)
}
Steps to reproduce
Snack or a link to a repository (optional)
https://github.com/atanaskanchev/rnu2
Unistyles version
next
React Native version
0.72.6
Platforms
iOS
You need to pod-install
:)
You need to
pod-install
:)
So I've tried:
npx expo prebuild
and- installed the pods
but still getting the same
I think it's because v2 is not correctly configured for npm. I was only working on local copy. Let me check that 👌
@atanaskanchev please try with:
yarn add react-native-unistyles@next // 2.0.0-alpha.6
yarn expo prebuild --clean
Unfortunately still the same with alpha 6 including Android.
Additionally I've noticed that the type of theme from useStyles comes as never
instead of UnistylesTheme
Have you seen instructions from #41 ?
Android is not ready yet.
Ah, I'm sorry, I've missed the Android JSI wrapper task 😇. but I've followed the install instructions from there though
No worries 😄 , let's find out the solution.
Here is an example config: https://github.com/jpudysz/react-native-unistyles/blob/2.0/examples/expo/src/styles/index.ts
In the same file you can use UnistylesRegistry
to register themes and breakpoints (TypeScript will guide you).
From now on, you can use createStyleSheet
and useStyles
imported from react-native-unistyles
.
If you have multiple themes you need to also call useInitialTheme
and thats it.
Do you have the same error that runtime is not available or something else?
I think I've followed all the steps in the repro repo, not sure what I'm missing
In the example config we've got
type AppThemes = {
light: typeof lightTheme
dark: typeof darkTheme
premium: typeof premiumTheme
}
declare module 'react-native-unistyles' {
export interface UnistylesThemes extends AppThemes {}
Can an interface extend a type in TS, not sure?
I'm checking your repo, will get back soon
I was able to run the example:
![image](https://private-user-images.githubusercontent.com/9088288/282855319-0730d2b1-1782-42d5-8592-fe9040da0713.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjI0MzUyNDQsIm5iZiI6MTcyMjQzNDk0NCwicGF0aCI6Ii85MDg4Mjg4LzI4Mjg1NTMxOS0wNzMwZDJiMS0xNzgyLTQyZDUtODU5Mi1mZTkwNDBkYTA3MTMucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDczMSUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDA3MzFUMTQwOTA0WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9YjU3NDM5YTI0OWFlMTM2MzQ1NzMwNzhkYjAwMDQ5MTQ0Mjc1YmIzNmEyMDJmMGZlMDM5OGU5MDk3MmNlMWE0YSZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.Sxpfqpvf7bd8MzD5-Vz3lwzMs8qTvfx8ZJsUQ_d2bdo)
I simply:
yarn
yarn expo prebuild
I'm getting TypeScript hints from the theme in createStyleSheet
.
There is indeed issue with theme
accessed from useStyles
- I need to fix it in the next version.
![image](https://private-user-images.githubusercontent.com/9088288/282859627-402c28fc-0cae-4a68-92c9-f07af845f335.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjI0MzUyNDQsIm5iZiI6MTcyMjQzNDk0NCwicGF0aCI6Ii85MDg4Mjg4LzI4Mjg1OTYyNy00MDJjMjhmYy0wY2FlLTRhNjgtOTJjOS1mMDdhZjg0NWYzMzUucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDczMSUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDA3MzFUMTQwOTA0WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9NzM5NDBjMDMyYWFkMjVmZjMxMzNiMWMwY2I5YTBmMWVkNWZhZDk3YzY5OTM0ZmRjMGFkMWEwYTFkODI2NzljZiZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.S1stAEbATJqQDXGCyuigebizbjsx9W6ImjWHSOYi4t0)
I was able to run your example.
The problem is that you didn't import anywhere /styles
folder so the UnistylesRegistry is not triggered. Your themes and breakpoints are empty.
To simply fix that add import:
import '../styles'
to the _layout.tsx, or import it somewhere else (some kind of index.ts file).
Unfortunately I'm still facing the issue after updating to alpha 7 and importing the styles. Will close it down as most probably there's some issue with my local setup. Thanks for your help @jpudysz