Description
Describe the bug
Description
In version 2.3.8 and above of @sveltejs/package
, certain path aliases are not being properly resolved during the packaging process. This worked correctly in version 2.3.7.
The issue affects .svelte.js
files, but is selective in which imports are transformed. Specifically, it appears that imports of files that re-export Svelte components are not being properly transformed to relative paths.
Reproduction
Reproduction
When packaging a library with svelte-package
, certain import paths in .svelte.js
files are not properly transformed to relative paths in the output.
Source file (.svelte.js file):
import { toSingleImageMeta } from '$lib/util/image/index.js';
import {
NetworkLoader
// ERROR_NOT_LOADED
// ERROR_TRANSFERRED
} from '$lib/classes/svkit/network-loader/index.js';
Output with version 2.3.7 (works correctly):
import { toSingleImageMeta } from '../../../util/image/index.js';
import {
NetworkLoader
// ERROR_NOT_LOADED
// ERROR_TRANSFERRED
} from '../network-loader/index.js';
Output with version 2.3.8 or higher (broken):
import { toSingleImageMeta } from '../../../util/image/index.js';
import {
NetworkLoader
// ERROR_NOT_LOADED
// ERROR_TRANSFERRED
} from '$lib/classes/svkit/network-loader/index.js';
Note that in the same file, some imports are correctly resolved while others are not.
Key Observation
- The
toSingleImageMeta
function is directly defined in the imported file, and its path is correctly transformed - The
NetworkLoader
import refers to a file that re-exports a Svelte component:// Contents of '$lib/classes/svkit/network-loader/index.js' export { default as NetworkLoader } from './NetworkLoader.svelte';
- Only the path that leads to a re-exported Svelte component fails to transform
This suggests the issue might be related to how the package build tool traces dependencies through re-exports that involve Svelte components.
Environment
- Node.js: 23.9.0
@sveltejs/package
: tested with 2.3.7 (working) vs 2.3.8+ (broken)- SvelteKit: 2.15.2 (peer dependency)
- Svelte: 5.20.5
Configuration
{
"devDependencies": {
"@sveltejs/adapter-auto": "^4.0.0",
"@sveltejs/package": "2.3.7",
"@sveltejs/vite-plugin-svelte": "^5.0.3",
"svelte": "^5.20.5",
"vite": "^6.2.0"
},
"peerDependencies": {
"@sveltejs/kit": "^2.15.2",
"svelte": "^5.0.0"
}
}
Workaround
For now, I've pinned my dependency to version 2.3.7:
"@sveltejs/package": "2.3.7"
I suspect this might be related to how paths that ultimately lead to Svelte components (even through re-exports) are handled differently in version 2.3.8+.
Logs
System Info
System:
OS: macOS 14.6.1
CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
Memory: 85.91 MB / 32.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 23.9.0 - /usr/local/bin/node
Yarn: 1.22.19 - /usr/local/bin/yarn
npm: 10.9.2 - /usr/local/bin/npm
pnpm: 10.5.2 - ~/Library/pnpm/pnpm
Browsers:
Chrome: 133.0.6943.142
Safari: 18.3
npmPackages:
@sveltejs/adapter-auto: ^4.0.0 => 4.0.0
@sveltejs/package: 2.3.8 => 2.3.8
@sveltejs/vite-plugin-svelte: ^5.0.3 => 5.0.3
svelte: ^5.20.5 => 5.20.5
vite: ^6.2.0 => 6.2.0
Severity
annoyance
Additional Information
No response