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

Error in Vitest with Astro (No "exports" main defined) #328

Closed
risu729 opened this issue Nov 2, 2023 · 6 comments
Closed

Error in Vitest with Astro (No "exports" main defined) #328

risu729 opened this issue Nov 2, 2023 · 6 comments
Labels
bug Something isn't working

Comments

@risu729
Copy link
Contributor

risu729 commented Nov 2, 2023

What happens

When I run npm knip with vitest.config.js with Astro integration, I get an error No "exports" main defined in repo\node_modules\tsconfck\package.json.
I tried to look into the problem but could not solve it. The cause is the jiti of loading Astro's dependency tsconfck.
I appreciate it if you could fix this issue, but please ignore it if it is difficult to resolve.

// vitest.config.js
import { getViteConfig } from "astro/config";
export default getViteConfig({});

Versions

Node.js v21.1.0
npm 10.2.0
knip: 2.38.6
astro: 3.4.2
vitest: 0.34.6
* All are the latest

Reproduction steps

The minimum reproduction repo is here. Just run npm i and npx knip.
I checked the reproduction both in Windows and Linux.

Error log

[*] Unresolved configuration (from CLI arguments)
{
  cwd: 'C:/Users/takua/GitHub/astro-vitest-knip-test',
  tsConfigFile: undefined,
  gitignore: true,
  isProduction: false,
  isStrict: false,
  isIgnoreInternal: false,
  isShowProgress: false,
  isIncludeEntryExports: false
}
[*] Included workspaces
[ 'astro-vitest-knip-test' ]
[*] Included workspace configs
[
  {
    pkgName: 'astro-vitest-knip-test',
    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 (.)
[ 'Astro', 'Vitest' ]
[.] Definition paths (0)
[]
[.] Entry paths in package.json (0)
[]
[.] Astro config file paths (0)
[]
[.] Astro dependencies (4)
[
  'entry:astro.config.{js,cjs,mjs,ts}',
  'entry:src/content/config.ts',
  'production:src/content/**/*.mdx',
  'production:src/pages/**/*.{astro,mdx,js,ts}'
]
[.] Vitest config file paths (1)
[ 'C:/Users/takua/GitHub/astro-vitest-knip-test/vitest.config.ts' ]
node:internal/modules/esm/resolve:294
  return new ERR_PACKAGE_PATH_NOT_EXPORTED(
         ^

Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports" main defined in C:\Users\takua\GitHub\astro-vitest-knip-test\node_modules\tsconfck\package.json
    at exportsNotFound (node:internal/modules/esm/resolve:294:10)
    at packageExportsResolve (node:internal/modules/esm/resolve:584:13)
    at resolveExports (node:internal/modules/cjs/loader:591:36)
    at Module._findPath (node:internal/modules/cjs/loader:668:31)
    at Module._resolveFilename (node:internal/modules/cjs/loader:1130:27)
    at Function.resolve (node:internal/modules/helpers:187:19)
    at _resolve (C:\Users\takua\GitHub\astro-vitest-knip-test\node_modules\jiti\dist\jiti.js:1:251148)
    at jiti (C:\Users\takua\GitHub\astro-vitest-knip-test\node_modules\jiti\dist\jiti.js:1:253746)
    at C:\Users\takua\GitHub\astro-vitest-knip-test\node_modules\astro\dist\core\config\tsconfig.js:2:17
    at evalModule (C:\Users\takua\GitHub\astro-vitest-knip-test\node_modules\jiti\dist\jiti.js:1:256443) {
  code: 'ERR_PACKAGE_PATH_NOT_EXPORTED'
}

Workaround

Add vitest: false to knip.ts

@risu729 risu729 added the bug Something isn't working label Nov 2, 2023
@webpro
Copy link
Collaborator

webpro commented Nov 3, 2023

So the issue is either in jiti or in tsconfck, not sure what I can do here in Knip.

Also not sure what is wrong with that exports config: https://github.com/dominikg/tsconfck/blob/main/packages/tsconfck/package.json#L18-L25

@risu729
Copy link
Contributor Author

risu729 commented Nov 3, 2023

I also struggled with it. I guess it's the problem of ESM/CJS compatibility...

@webpro
Copy link
Collaborator

webpro commented Nov 4, 2023

Seeing the same issue in an Astro project when importing @mdx-js/mdx (v2 or v3):

***/knip/dist/util/loader.js:31
        throw new LoaderError(`Error loading ${filePath}`, { cause: error });
              ^

LoaderError: Error loading ***/knip.ts
    at load (***/knip/dist/util/loader.js:31:15)
    at ConfigurationChief.loadResolvedConfigurationFile (***/knip/dist/ConfigurationChief.js:102:35)
    ... 3 lines matching cause stack trace ...
    at async ***/knip/dist/cli.js:73:1 {
  [cause]: Error: No "exports" main defined in ***/node_modules/estree-walker/package.json

@webpro
Copy link
Collaborator

webpro commented Nov 8, 2023

Might be related to or duplicate of #290.

@webpro
Copy link
Collaborator

webpro commented Nov 13, 2023

🚀 This issue has been resolved in v2.41.2. See Release 2.41.2 for release notes.

@webpro webpro closed this as completed in 7a537a6 Nov 13, 2023
@risu729
Copy link
Contributor Author

risu729 commented Nov 14, 2023

I confirmed that the issue is resolved. Thank you so much!!!

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