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

🐛 expo - Knip fails to run in an Expo app with a configurable app.config.js #919

Open
6 tasks done
ronbraha opened this issue Jan 20, 2025 · 3 comments
Open
6 tasks done
Labels
bug Something isn't working

Comments

@ronbraha
Copy link

Prerequisites

Reproduction url

https://github.com/ronbraha/knip-expo-issue

Reproduction access

  • I've made sure the reproduction is publicly accessible

Description of the issue

Since version 5.42.0, Knip fails to run in an expo app with an app.config.js that accepts a function with a config object.
The errors vary from version 5.42.0 to the latest (5.42.2), as there was an attempt to address this in the newest version.

This is what I see in 5.42.2 with a new app created with create-expo-app, and I experience the same issue in a production app:

module.exports = ({ config }) => config;
                    ^

TypeError: Cannot destructure property 'config' of 'undefined' as it is undefined.
    at module.exports (/Users/ronbraha/Code/debugging/knip-issue/app.config.js:1:21)
    at Object.resolveEntryPaths (file:///Users/ronbraha/Code/debugging/knip-issue/node_modules/knip/dist/plugins/expo/index.js:12:60)
    at runPlugin (file:///Users/ronbraha/Code/debugging/knip-issue/node_modules/knip/dist/WorkspaceWorker.js:246:85)
    at async WorkspaceWorker.findDependenciesByPlugins (file:///Users/ronbraha/Code/debugging/knip-issue/node_modules/knip/dist/WorkspaceWorker.js:281:13)
    at async main (file:///Users/ronbraha/Code/debugging/knip-issue/node_modules/knip/dist/index.js:120:41)
    at async run (file:///Users/ronbraha/Code/debugging/knip-issue/node_modules/knip/dist/cli.js:26:83)
    at async file:///Users/ronbraha/Code/debugging/knip-issue/node_modules/knip/dist/cli.js:104:1
@ronbraha ronbraha added the bug Something isn't working label Jan 20, 2025
@webpro
Copy link
Collaborator

webpro commented Jan 20, 2025

Thanks @ronbraha.

Yeah after I found out that it can be a function indeed I added a fix in 5.42.2.

The provided rep(r)o has a app.json - does that give issues as well?

Either way, any chance you're up for a PR to fix this? Apparently my attempt was too naive to fix all cases:

const expoConfig = typeof localConfig === 'function' ? localConfig() : localConfig;
const config = 'expo' in expoConfig ? expoConfig.expo : expoConfig;

@ronbraha
Copy link
Author

I can point out the problem and say it occurs because the referenced code here tries to call localConfig as a function but doesn't pass the options parameter containing the config object. How would Knip access this configuration object if you want to parse it? Still, it's possible that an empty object like calling localConfig({ config: /* pass the "app.json" here? */ }) may have performed better, as now the problem is that destructuring the config field from an undefined parameter crashes.

@webpro
Copy link
Collaborator

webpro commented Jan 20, 2025

The localConfig in the Knip Expo plugin is whatever resolves to the default export of app.json or app.config.js.

Would be great if you could either 1) debug that using Knip in the production app, or 2) create a an actual reproduction of that situation I could look into.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants