-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Description
Describe the bug
When packaging with @sveltejs/package (versions 2.5.1 or higher), path aliases are not resolved for certain import statements, which breaks the package on the consumer side.
The issue was introduced with #14413.
Reproduction
Setup
Assume we have the following alias configuration in svelte.config.js:
alias: {
$foo: "./src/lib/foo",
}Assume we have a .ts or .svelte file in the root of ./src/lib with either one of the following import statements (all valid, as per MDN Docs):
import foo, { bar } from '$foo'
import foo, { bar, baz } from '$foo'
import foo, { type bar, type baz } from '$foo'
import foo, * as bar from '$foo'
import _foo from '$foo'
import * as _foo from '$foo'
import '$foo'Current result after packaging
None of the path aliases have been resolved.
import foo, { bar } from '$foo'
import foo, { bar, baz } from '$foo'
import foo, { type bar, type baz } from '$foo'
import foo, * as bar from '$foo'
import _foo from '$foo'
import * as _foo from '$foo'
import '$foo'Expected result after packaging
All path aliases have been resolved.
import foo, { bar } from './foo'
import foo, { bar, baz } from './foo'
import foo, { type bar, type baz } from './foo'
import foo, * as bar from './foo'
import _foo from './foo'
import * as _foo from './foo'
import './foo'Root cause
The current regular expression that identifies path aliases does not seem to capture the following:
- Combinations of default and
named¹/namespaced imports - Default/namespaced imports with identifiers that start with
_ - Side-effect-only imports
¹) See #14455 (comment)
Workaround
As a workaround, you can use @sveltejs/package@2.5.0 or rewrite any affected import statements (if possible) so that they are captured by the current regular expression.
Logs
System Info
System:
OS: macOS 15.6.1
CPU: (12) arm64 Apple M4 Pro
Memory: 192.52 MB / 24.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 22.16.0 - ~/.nvm/versions/node/v22.16.0/bin/node
npm: 11.4.1 - ~/.nvm/versions/node/v22.16.0/bin/npm
Browsers:
Chrome: 140.0.7339.133
Edge: 140.0.3485.66
Safari: 18.6Severity
serious, but I can work around it
Additional Information
No response