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

Stack breaks typescript in v2 #24933

Closed
lhguerra opened this issue Oct 18, 2023 · 15 comments
Closed

Stack breaks typescript in v2 #24933

lhguerra opened this issue Oct 18, 2023 · 15 comments
Labels
needs review Issue is ready to be reviewed by a maintainer Router expo-router

Comments

@lhguerra
Copy link

Minimal reproducible example

https://github.com/lhguerra/expo-router-stack-typescript-bug

Which package manager are you using? (Yarn is recommended)

npm

If the issue is web-related, please select the bundler (web.bundler in the app.json)

metro

Summary

When adding Stack component to the _layout, it breaks the type check with a bunch of errors in expo-router lib.

Just download the repository above, install the dependencies and run npm run lint:ts

Environment

expo-env-info 1.0.5 environment info:
System:
OS: Linux 5.15 Ubuntu 22.04.3 LTS 22.04.3 LTS (Jammy Jellyfish)
Shell: 5.8.1 - /usr/bin/zsh
Binaries:
Node: 18.16.0 - ~/.nvm/versions/node/v18.16.0/bin/node
npm: 9.5.1 - ~/.nvm/versions/node/v18.16.0/bin/npm
npmPackages:
expo: ^49.0.3 => 49.0.13
react: 18.2.0 => 18.2.0
react-dom: 18.2.0 => 18.2.0
react-native: 0.72.3 => 0.72.3
react-native-web: ~0.19.6 => 0.19.9
npmGlobalPackages:
eas-cli: 5.0.2
expo-cli: 6.3.10
Expo Workflow: managed

@lhguerra lhguerra added needs validation Issue needs to be validated Router expo-router labels Oct 18, 2023
@expo-bot expo-bot added needs review Issue is ready to be reviewed by a maintainer and removed needs validation Issue needs to be validated labels Oct 18, 2023
@lhguerra
Copy link
Author

The repo was missing one commit, just sent it

@lhguerra
Copy link
Author

I'll have to roll everything back to react navigation :/

@lhguerra
Copy link
Author

This page should have a warning sayng that expo router is still beta and not production ready
https://docs.expo.dev/routing/introduction/

@buraks
Copy link
Contributor

buraks commented Oct 21, 2023

I cloned the repo, ran npm install, there is no type error. You might want to check your local setup

@buraks
Copy link
Contributor

buraks commented Oct 21, 2023

I just saw that it's when you run npm run lint:ts, I made the lint work ok by adding bunch of types to dev dependencies:

    "@expo/config": "^8.1.2",
    "@expo/config-plugins": "^7.2.5",
    "@types/react": "^18.0.25",
    "@types/react-native": "^0.70.6",
    "@types/url-parse": "^1.4.10"

not sure which ones are actually useful

@lhguerra
Copy link
Author

I tried it but still get the same errors :/

@hichemfantar
Copy link
Contributor

I get the type errors when I import tabs for some reason #25213

@hichemfantar
Copy link
Contributor

hichemfantar commented Nov 17, 2023

I created a script to ignore expo-router type errors when type checking (sdk49) it's a bit hacky but it'll have to do until we upgrade to sdk50 which should have the problem fixed, I had to do this because I couldn't ignore the errors using tsconfig exclude and ts-ignore:
package.json script:

"build": "tsc -v && (tsc --noEmit --pretty > tsc_output.txt) || (cat tsc_output.txt; echo \"\ntsc failed, attempting manual resolution...\"; bash tsc_check.sh)"

tsc_check.sh file:

#!/bin/bash

# Check if the "Errors  Files" line exists at the start
if grep -q "Errors  Files" tsc_output.txt; then
    # Save the number of lines containing "expo-router" errors
    expo_router_error_count=$(awk '/Errors  Files/ {flag=1; next} flag && /expo-router/ {count++} END {print count}' tsc_output.txt)
    
    # Save the number of lines after "Errors  Files"
    lines_after_errors_files=$(awk '/Errors  Files/ {flag=1; next} flag {count++} END {print count}' tsc_output.txt)
    
    # Check if the counts are equal
    if [ "$expo_router_error_count" -eq "$lines_after_errors_files" ]; then
        echo "Number of 'expo-router' errors is equal to the number of lines after 'Errors  Files'. Proceeding with 'tsc' command."
        exit 0
    else
        echo "Number of 'expo-router' errors is not equal to the number of lines after 'Errors  Files'. Exiting 'tsc' command."
        exit 1
    fi
else
    echo "The 'Errors  Files' line does not exist. Proceeding with 'tsc' command."
    exit 0
fi

@EvanBacon
Copy link
Contributor

Duplicate of #25478 -- we've published the alpha of v3, if you're truly blocked then you can try upgrading today.

@lhguerra
Copy link
Author

how can this be the duplicate if it is way older?

@abumalick
Copy link
Contributor

@EvanBacon It is very strange to be forced to upgrade to an alpha version to fix types checks from node_modules folder.
We are ignoring "node_modules" folder and have skipLibCheck to true. How come we have errors like that?

@abumalick
Copy link
Contributor

All right, I fixed the errors by changing my import from

import {Stack} from "expo-router/stack";

to

import {Stack} from "expo-router";

I believe I was importing a ts file and it was causing the problems.

This comment helped me: microsoft/TypeScript#40426 (comment)

@hichemfantar
Copy link
Contributor

I created a script to ignore expo-router type errors when type checking (sdk49) it's a bit hacky but it'll have to do until we upgrade to sdk50 which should have the problem fixed, I had to do this because I couldn't ignore the errors using tsconfig exclude and ts-ignore: package.json script:

"build": "tsc -v && (tsc --noEmit --pretty > tsc_output.txt) || (cat tsc_output.txt; echo \"\ntsc failed, attempting manual resolution...\"; bash tsc_check.sh)"

tsc_check.sh file:

#!/bin/bash

# Check if the "Errors  Files" line exists at the start
if grep -q "Errors  Files" tsc_output.txt; then
    # Save the number of lines containing "expo-router" errors
    expo_router_error_count=$(awk '/Errors  Files/ {flag=1; next} flag && /expo-router/ {count++} END {print count}' tsc_output.txt)
    
    # Save the number of lines after "Errors  Files"
    lines_after_errors_files=$(awk '/Errors  Files/ {flag=1; next} flag {count++} END {print count}' tsc_output.txt)
    
    # Check if the counts are equal
    if [ "$expo_router_error_count" -eq "$lines_after_errors_files" ]; then
        echo "Number of 'expo-router' errors is equal to the number of lines after 'Errors  Files'. Proceeding with 'tsc' command."
        exit 0
    else
        echo "Number of 'expo-router' errors is not equal to the number of lines after 'Errors  Files'. Exiting 'tsc' command."
        exit 1
    fi
else
    echo "The 'Errors  Files' line does not exist. Proceeding with 'tsc' command."
    exit 0
fi

I built this script specifically to ignore the router type errors

@hichemfantar
Copy link
Contributor

All right, I fixed the errors by changing my import from

import {Stack} from "expo-router/stack";

to

import {Stack} from "expo-router";

I believe I was importing a ts file and it was causing the problems.

This comment helped me: microsoft/TypeScript#40426 (comment)

this doesn't fix tabs for me
https://docs.expo.dev/router/advanced/tabs/

@marklawlor
Copy link
Contributor

Should be resolved in Expo Router v3.

If you are still having this issue with version 3, can you please create a new issue with a reproduction repo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs review Issue is ready to be reviewed by a maintainer Router expo-router
Projects
None yet
Development

No branches or pull requests

7 participants