Closed janosh closed 1 year ago
It's correct because @sveltejs/package
does not provide any JS to import, just types. Do you have import { .. } from '@sveltejs/package'
anywhere by chance? Does it help to turn it into import type { .. } from '@sveltejs/package'
?
Without a reproducible we can't really help you.
This happened to me as well with sveltekit-flash-message when updating to vitest ^0.34.1
, and now with @sveltejs/package
.
I opened an issue at https://github.com/vitest-dev/vitest/issues/3913 and got the explanation that Vitest didn't respect optimized dependencies in previous versions.
By adding a top-level export for sveltekit-flash-message and publishing a new patch version, it seems to work fine.
Edit: Version is "@sveltejs/package": "^2.2.0"
@dominikg I believe vite-plugin-svelte does the automatic addition of these dependencies, right? Would it be possible to exclude packages which have an exports map that only includes types
conditions? Also I don't understand from that issue link what optimized dependencies have to do with a required .
export in your exports map.
v-p-s only adds deps that have a svelte condition or use the svelte toplevel field, svelte-package should have neither. without a reproduction it's hard to tell what's going on here, it should not be a dependency of an application that is being built.
regarding optimizeDeps and requiring a . export, this is something to check with vite, cc @bluwy
@dominikg Maybe it's not the reproduction you have in mind, but it's simple to reproduce the error I encountered:
pnpm create svelte@latest
(Library project, include Vitest)^0.34.1
pnpm vitest
Results in:
Error: Failed to resolve entry for package "@sveltejs/package". The package may have incorrect main/module/exports specified in its package.json: No known conditions for "." specifier in "@sveltejs/package" package
❯ packageEntryFailure node_modules/.pnpm/vite@4.4.9_@types+node@20.4.9/node_modules/vite/dist/node/chunks/dep-df561101.js:28691:11
❯ resolvePackageEntry node_modules/.pnpm/vite@4.4.9_@types+node@20.4.9/node_modules/vite/dist/node/chunks/dep-df561101.js:28686:9
❯ tryNodeResolve node_modules/.pnpm/vite@4.4.9_@types+node@20.4.9/node_modules/vite/dist/node/chunks/dep-df561101.js:28419:20
❯ Context.resolveId node_modules/.pnpm/vite@4.4.9_@types+node@20.4.9/node_modules/vite/dist/node/chunks/dep-df561101.js:28180:28
❯ Object.resolveId node_modules/.pnpm/vite@4.4.9_@types+node@20.4.9/node_modules/vite/dist/node/chunks/dep-df561101.js:44207:64
❯ async file:/E:/Projects/TEST/lib-vitest/node_modules/.pnpm/vite@4.4.9_@types+node@20.4.9/node_modules/vite/dist/node/chunks/dep-df561101.js:65837:21
❯ async file:/E:/Projects/TEST/lib-vitest/node_modules/.pnpm/vite@4.4.9_@types+node@20.4.9/node_modules/vite/dist/node/chunks/dep-df561101.js:44852:20
❯ addManuallyIncludedOptimizeDeps node_modules/.pnpm/vite@4.4.9_@types+node@20.4.9/node_modules/vite/dist/node/chunks/dep-df561101.js:46034:31
❯ optimizeServerSsrDeps node_modules/.pnpm/vite@4.4.9_@types+node@20.4.9/node_modules/vite/dist/node/chunks/dep-df561101.js:45638:5
❯ createDevSsrDepsOptimizer node_modules/.pnpm/vite@4.4.9_@types+node@20.4.9/node_modules/vite/dist/node/chunks/dep-df561101.js:45556:22
moved the issue to vite-plugin-svelte.
It looks likevitefu
adds @sveltejs/package
and svelte2tsx
to ssr.noExternal
vite:vite-plugin-svelte extra config for dependencies generated by vitefu {
optimizeDeps: {
include: [
'@sveltejs/package > chokidar',
'@sveltejs/package > semver',
'@sveltejs/package > svelte2tsx > dedent-js'
],
exclude: []
},
ssr: {
noExternal: [ '@sveltejs/package', 'svelte2tsx' ],
external: [
'chokidar',
'kleur',
'sade',
'semver',
'dedent-js',
'pascal-case'
]
}
}
and vite adds packages present in ssr.noExternal to optimizeDeps.include.
We may have to update some config or change the filter functions we use with vitefu to prevent these from showing up. I'm also a bit confused about some of the values in ssr.external.
If the error is coming from Vitest 0.34 specifically, it's likely because that version started to use ssr.external
and ssr.noExternal
, instead of deps.external
and deps.inline
, that's causing these errors. Vite's ssr
configs are usually lazy, so setting these packages incorrectly is fine as long as you don't import it, but Vitest seems to made it eager (which I don't exactly think it's a bug there).
The PR fix sent is probably the simplest way to fix this though.
released fix in 2.4.5 please let us know if you still have this issue aftert updating
Works fine for me now, thank you for the quick fix!
released fix in 2.4.5 please let us know if you still have this issue aftert updating
I'm having the same issue :
Failed to resolve entry for package "sveltekit-flash-message". The package may have incorrect main/module/exports specified in its package.json: No known conditions for "." specifier in "sveltekit-flash-message" package
Packages :
{
"@sveltejs/kit": "1.25.1",
"svelte": "4.2.1",
"sveltekit-flash-message": "2.2.1",
"vite": "4.4.10",
}
Describe the bug
I started running into
Stacktrace
``` ❯ packageEntryFailure node_modules/vite/dist/node/chunks/dep-df561101.js:28691:11 ❯ resolvePackageEntry node_modules/vite/dist/node/chunks/dep-df561101.js:28686:9 ❯ tryNodeResolve node_modules/vite/dist/node/chunks/dep-df561101.js:28419:20 ❯ Context.resolveId node_modules/vite/dist/node/chunks/dep-df561101.js:28[18](https://github.com/janosh/elementari/actions/runs/5791065675/job/15695238618?pr=42#step:5:19)0:28 ❯ Object.resolveId node_modules/vite/dist/node/chunks/dep-df561101.js:44207:64 ❯ async file:/home/runner/work/elementari/elementari/node_modules/vite/dist/node/chunks/dep-df561101.js:65837:21 ❯ async file:/home/runner/work/elementari/elementari/node_modules/vite/dist/node/chunks/dep-df561101.js:44852:[20](https://github.com/janosh/elementari/actions/runs/5791065675/job/15695238618?pr=42#step:5:21) ❯ addManuallyIncludedOptimizeDeps node_modules/vite/dist/node/chunks/dep-df561101.js:46034:31 ❯ optimizeServerSsrDeps node_modules/vite/dist/node/chunks/dep-df561101.js:45638:5 ❯ createDevSsrDepsOptimizer node_modules/vite/dist/node/chunks/dep-df561101.js:45556:[22](https://github.com/janosh/elementari/actions/runs/5791065675/job/15695238618?pr=42#step:5:23) ```I'm no packaging expert but looking at
https://github.com/sveltejs/kit/blob/a6fe5fcb1c7258281b4bf53b94543272e6e6c6d8/packages/package/package.json#L44-L50
isn't that missing an
"import": "./src/exports/index.js"
or similar (going bykit
exports).https://github.com/sveltejs/kit/blob/a6fe5fcb1c7258281b4bf53b94543272e6e6c6d8/packages/kit/package.json#L75-L100
Reproduction
Tried but failed to repro on StackBlitz.
Logs
No response
System Info
Severity
blocking all usage of SvelteKit
Additional Information
No response