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

TypeError in vite.config.ts #303

Closed
robcmills opened this issue Oct 18, 2023 · 9 comments
Closed

TypeError in vite.config.ts #303

robcmills opened this issue Oct 18, 2023 · 9 comments
Labels
bug Something isn't working

Comments

@robcmills
Copy link

When I run knip I get the following error:

yarn run v1.22.19
$ knip
Analyzing workspace ....
/Users/robcmills/src/openspace/web/icedemon/vite.config.ts:50
(0, _vite.defineConfig)(async ({ command, mode }) => {
                                 ^

TypeError: Cannot destructure property 'command' of 'undefined' as it is undefined.
    at /Users/robcmills/src/openspace/web/icedemon/vite.config.ts:50:34
    at findVitestDeps (file:///Users/robcmills/src/openspace/web/icedemon/node_modules/knip/dist/plugins/vitest/index.js:13:55)
    at Module.findViteDependencies (file:///Users/robcmills/src/openspace/web/icedemon/node_modules/knip/dist/plugins/vite/index.js:12:12)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async WorkspaceWorker.findDependenciesByPlugins (file:///Users/robcmills/src/openspace/web/icedemon/node_modules/knip/dist/WorkspaceWorker.js:191:46)
    at async WorkspaceWorker.findAllDependencies (file:///Users/robcmills/src/openspace/web/icedemon/node_modules/knip/dist/WorkspaceWorker.js:216:9)
    at async main (file:///Users/robcmills/src/openspace/web/icedemon/node_modules/knip/dist/index.js:109:30)
    at async run (file:///Users/robcmills/src/openspace/web/icedemon/node_modules/knip/dist/cli.js:24:73)
    at async file:///Users/robcmills/src/openspace/web/icedemon/node_modules/knip/dist/cli.js:73:1

Node.js v20.8.0

With the following config:

const config: KnipConfig = {
  // Files we get the exports from
  project: ['src/js/**'],
  // Entry paths to crawl and check whether exports are used
  entry: [
    'src/js/main/MainEntry.tsx',
    // These are used by bash scripts, so we consider each of them entry files
    'src/js/i18n/lokalise/*',
    'src/js/i18n/transform/*',
    'src/js/i18n/eslint-plugin-translate/*',
  ],
  // Unused exports in these files are ignored
  ignore: ['src/js/openapi/generated/**', 'vite.config.ts'],
  ignoreExportsUsedInFile: true,
  // These rules are useful but they either don't work quite right yet or too
  // much to fix. We can revisit and turn them on in the future.
  rules: {
    binaries: 'off',
    unlisted: 'off',
    dependencies: 'off',
  },
  // disable plugins
  vite: false,
};

As you can see, I am trying to just ignore this file, and turn off the plugin, but neither seem to be working. And I get the same error also when not trying to ignore or turn off plugin.

Not sure what additional info would be helpful to debug this, but happy to provide more if requested.

@robcmills robcmills added the bug Something isn't working label Oct 18, 2023
@robcmills
Copy link
Author

Debug output:

yarn run v1.22.19
$ knip --debug
[*] Unresolved configuration (from CLI arguments)
{
  cwd: '/Users/robcmills/src/openspace/web/icedemon',
  tsConfigFile: undefined,
  gitignore: true,
  isProduction: false,
  isStrict: false,
  isIgnoreInternal: false,
  isShowProgress: false,
  isIncludeEntryExports: false
}
[*] Included workspaces
[ 'openspace' ]
[*] Included workspace configs
[
  {
    pkgName: 'openspace',
    name: '.',
    config: {
      entry: [
        '{index,cli,main}.{js,mjs,cjs,jsx,ts,tsx,mts,cts}!',
        'src/{index,cli,main}.{js,mjs,cjs,jsx,ts,tsx,mts,cts}!'
      ],
      project: [ '**/*.{js,mjs,cjs,jsx,ts,tsx,mts,cts}!' ],
      paths: {},
      ignore: [],
      ignoreBinaries: [],
      ignoreDependencies: []
    },
    ancestors: []
  }
]
[.] Enabled plugins (.)
[
  'Babel',      'Cypress',
  'ESLint',     'Jest',
  'Prettier',   'Sentry',
  'TypeScript', 'Vite',
  'Webpack'
]
[.] Definition paths (14)
[
  '/Users/robcmills/src/openspace/web/icedemon/src/js/forge/ForgeViewer.d.ts',
  '/Users/robcmills/src/openspace/web/icedemon/src/js/typings/async-retry.d.ts',
  '/Users/robcmills/src/openspace/web/icedemon/src/js/typings/colormap.d.ts',
  '/Users/robcmills/src/openspace/web/icedemon/src/js/typings/exif-parser.d.ts',
  '/Users/robcmills/src/openspace/web/icedemon/src/js/typings/js-cookie.d.ts',
  '/Users/robcmills/src/openspace/web/icedemon/src/js/typings/json-view.d.ts',
  '/Users/robcmills/src/openspace/web/icedemon/src/js/typings/kd.tree.d.ts',
  '/Users/robcmills/src/openspace/web/icedemon/src/js/typings/nprogress.d.ts',
  '/Users/robcmills/src/openspace/web/icedemon/src/js/typings/react-dates.d.ts',
  '/Users/robcmills/src/openspace/web/icedemon/src/js/typings/react-input-switch.d.ts',
  '/Users/robcmills/src/openspace/web/icedemon/src/js/typings/react-load-script.d.ts',
  '/Users/robcmills/src/openspace/web/icedemon/src/js/typings/react.d.ts',
  '/Users/robcmills/src/openspace/web/icedemon/src/js/typings/scrollbar-width.d.ts',
  '/Users/robcmills/src/openspace/web/icedemon/src/js/typings/vector.d.ts'
]
[.] Glob options
{
  cwd: '/Users/robcmills/src/openspace/web/icedemon',
  globPatterns: [ 'build/bundle.js' ],
  ignorePatterns: [ '**/node_modules/**', '.yarn' ]
}
[.] Entry paths in package.json (0)
[]
[.] Babel config file paths (1)
[ '/Users/robcmills/src/openspace/web/icedemon/babel.config.js' ]
[.] Babel dependencies (9)
[
  '@babel/plugin-proposal-class-properties',
  '@babel/plugin-proposal-nullish-coalescing-operator',
  '@babel/plugin-proposal-optional-chaining',
  '@babel/plugin-proposal-private-methods',
  '@babel/plugin-proposal-private-property-in-object',
  '@babel/plugin-syntax-dynamic-import',
  '@babel/preset-env',
  '@babel/preset-react',
  '@babel/preset-typescript'
]
[.] Cypress config file paths (1)
[ '/Users/robcmills/src/openspace/web/icedemon/cypress.config.cjs' ]
[.] Cypress dependencies (4)
[
  'entry:./e2e/cypress/component/**/*.cy.tsx',
  'entry:./e2e/cypress/e2e/**/*.cy.ts',
  'entry:cypress/plugins/index.js',
  'entry:cypress/support/e2e.{js,jsx,ts,tsx}'
]
[.] ESLint config file paths (1)
[ '/Users/robcmills/src/openspace/web/icedemon/.eslintrc.json' ]
[.] ESLint dependencies (12)
[
  '@typescript-eslint/eslint-plugin',
  '@typescript-eslint/parser',
  'eslint',
  'eslint-config-prettier',
  'eslint-plugin-cypress/recommended',
  'eslint-plugin-jest',
  'eslint-plugin-prettier/recommended',
  'eslint-plugin-query',
  'eslint-plugin-react',
  'eslint-plugin-react-hooks',
  'eslint-plugin-simple-import-sort',
  'eslint-plugin-translate'
]
[.] Jest config file paths (1)
[ '/Users/robcmills/src/openspace/web/icedemon/jest.config.js' ]
[.] Jest dependencies (6)
[
  '/Users/robcmills/src/openspace/web/icedemon//jest-resolver.js',
  'babel-jest',
  'entry:**/?(*.)+(spec|test).[jt]s?(x)',
  'entry:**/__tests__/**/*.[jt]s?(x)',
  'jest-environment-jsdom',
  'ts-jest/jest-preset'
]
[.] Prettier config file paths (1)
[ '/Users/robcmills/src/openspace/web/icedemon/.prettierrc.json' ]
[.] Prettier dependencies (0)
[]
[.] Sentry config file paths (0)
[]
[.] Sentry dependencies (1)
[ 'entry:sentry.{client,server,edge}.config.{js,ts}' ]
[.] TypeScript config file paths (1)
[ '/Users/robcmills/src/openspace/web/icedemon/tsconfig.json' ]
[.] TypeScript dependencies (3)
[ 'jest', 'node', 'webpack-env' ]
[.] Vite config file paths (1)
[ '/Users/robcmills/src/openspace/web/icedemon/vite.config.ts' ]
[.] Vite dependencies (0)
[]
/Users/robcmills/src/openspace/web/icedemon/vite.config.ts:50
(0, _vite.defineConfig)(async ({ command, mode }) => {
                                 ^

TypeError: Cannot destructure property 'command' of 'undefined' as it is undefined.
    at /Users/robcmills/src/openspace/web/icedemon/vite.config.ts:50:34
    at findVitestDeps (file:///Users/robcmills/src/openspace/web/icedemon/node_modules/knip/dist/plugins/vitest/index.js:13:55)
    at Module.findViteDependencies (file:///Users/robcmills/src/openspace/web/icedemon/node_modules/knip/dist/plugins/vite/index.js:12:12)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async WorkspaceWorker.findDependenciesByPlugins (file:///Users/robcmills/src/openspace/web/icedemon/node_modules/knip/dist/WorkspaceWorker.js:191:46)
    at async WorkspaceWorker.findAllDependencies (file:///Users/robcmills/src/openspace/web/icedemon/node_modules/knip/dist/WorkspaceWorker.js:216:9)
    at async main (file:///Users/robcmills/src/openspace/web/icedemon/node_modules/knip/dist/index.js:109:30)
    at async run (file:///Users/robcmills/src/openspace/web/icedemon/node_modules/knip/dist/cli.js:24:73)
    at async file:///Users/robcmills/src/openspace/web/icedemon/node_modules/knip/dist/cli.js:73:1

Node.js v20.8.0
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

@robcmills
Copy link
Author

Ah, my knip config was named knip-config.ts and so was not being found. By providing it in a cli arg I was able to get the ignore to work:

knip --config knip-config.ts

@webpro
Copy link
Collaborator

webpro commented Oct 18, 2023

Glad you found it.

(async ({ command, mode })`

But it's still very useful for me to see this bug report, didn't realize yet that you can provide an (async) function there :)

@webpro
Copy link
Collaborator

webpro commented Oct 18, 2023

🚀 This issue has been resolved in v2.35.0. See Release 2.35.0 for release notes.

@webpro webpro closed this as completed in 7b1686b Oct 18, 2023
@webpro
Copy link
Collaborator

webpro commented Oct 18, 2023

Should not need to ignore anymore :)

@risu729
Copy link
Contributor

risu729 commented Oct 19, 2023

I got the same error in vitest.config.ts with knip 2.35.0.
Could you support the same syntax, async config and conditional config, also in the Vitest plugin?

@robcmills
Copy link
Author

🚀 This issue has been resolved in v2.35.0. See Release 2.35.0 for release notes.

Thanks @webpro . I confirmed that on latest version of knip I was able to not ignore vite config and it seems to be working now 👍 👏

@webpro
Copy link
Collaborator

webpro commented Oct 24, 2023

Awesome

@risu729
Copy link
Contributor

risu729 commented Nov 2, 2023

Thank you for fixing the issue for Vitest! I'm sorry for not getting back to you sooner.
Unfortunately, I got an error with Astro, so I opened issue #328.

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

3 participants