Skip to content

fix: identify circular imports from src/env - #6

Open
anurag6569201 wants to merge 1 commit into
qa/agent-sveltejs-kit/pr-06-17014/basefrom
qa/agent-sveltejs-kit/pr-06-17014/head
Open

anurag6569201 wants to merge 1 commit into
qa/agent-sveltejs-kit/pr-06-17014/basefrom
qa/agent-sveltejs-kit/pr-06-17014/head

Conversation

@anurag6569201

Copy link
Copy Markdown

Fixes sveltejs#17013.

When src/env imports a dependency that imports $app/env/private or $app/env/public, loading the environment configuration depends on modules that have not yet been generated.

Recognize this resolution failure and report the circular dependency directly instead of exposing the internal generated-module path. When available, the diagnostic now identifies the project-relative module that imported $app/env/private or $app/env/public.

A regression test covers the transitive helper-import pattern and verifies that the responsible helper module is reported.

Testing

  • pnpm vitest run -c vitest.kit.config.js src/core/sync/sync.spec.js --reporter=verbose
  • pnpm -F @sveltejs/kit test:unit
  • pnpm format
  • pnpm -F @sveltejs/kit lint
  • pnpm -F @sveltejs/kit prepublishOnly

Source merge-base: 2df68224d77558ce6a0fc21513c5cd7f299c60d1
Source head: 2c90fd575e104fd3c4be91756495774e8585d906

@shipwright-agent

Copy link
Copy Markdown

✅ Shipwright · Approve

Recommendation: approve PR #6 · Tier T1
Checks: 0 total · 0 needing attention

Next step: ready to merge.

Findings (4)

  • HIGH The regex /<sveltekit:generated>/env/(private|public)/server.js/ is a magic internal path pattern with no comment explaining why this exact generated path indicates a circular · packages/kit/src/core/env.js:113
    • Fix: Review the cited evidence, fix the risk if confirmed, and rerun Shipwright.
  • HIGH The new resolveId hook records the importer for $app/env/private or public, but it never clears or scopes env_importers per resolution. · packages/kit/src/core/env.js:70
    • Fix: Review the cited evidence, fix the risk if confirmed, and rerun Shipwright.
  • HIGH The error path now only special-cases ERR_MODULE_NOT_FOUND. · packages/kit/src/core/env.js:112
    • Fix: Review the cited evidence, fix the risk if confirmed, and rerun Shipwright.
  • HIGH The new test writes a temporary env entry and helper under node_modules/.svelte-kit-env-* inside the real basics app directory. · packages/kit/src/core/sync/sync.spec.js:41
    • Fix: Review the cited evidence, fix the risk if confirmed, and rerun Shipwright.

Fireworks usage: 7,819 input · 462 output · 8,281 total tokens · $0.0020 · 9s · 0 fix iteration(s)

Open the Shipwright check for full evidence and the audit bundle. Use /shipwright rerun to verify again.

`Cannot import \`$app/*\` modules other than \`$app/env\` inside \`src/env\``,
{ cause: e }
if (error.code === 'ERR_MODULE_NOT_FOUND') {
const match = error.message?.match(

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shipwright · HIGH

The regex /<sveltekit:generated>/env/(private|public)/server.js/ is a magic internal path pattern with no comment explaining why this exact generated path indicates a circular

Impact: The regex /<sveltekit:generated>/env/(private|public)/server.js/ is a magic internal path pattern with no comment explaining why this exact generated path indicates a circular dependency. A future maintainer cannot tell whether the pattern is complete or will silently break if the generated path changes.

Suggested fix: Review the cited evidence, fix the risk if confirmed, and rerun Shipwright.

plugins: [
{
name: 'dependency-scanner',
enforce: 'pre',

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shipwright · HIGH

The new resolveId hook records the importer for $app/env/private or public, but it never clears or scopes env_importers per resolution.

Impact: The new resolveId hook records the importer for $app/env/private or public, but it never clears or scopes env_importers per resolution. If the same load_explicit_env call resolves the same virtual module from multiple importers, the map will retain only the last importer, so the eventual circular-dependency error can blame the wrong file. This makes the diagnostic misleading in multi-import scenarios.

Suggested fix: Review the cited evidence, fix the risk if confirmed, and rerun Shipwright.

throw new Error(
`Cannot import \`$app/*\` modules other than \`$app/env\` inside \`src/env\``,
{ cause: e }
if (error.code === 'ERR_MODULE_NOT_FOUND') {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shipwright · HIGH

The error path now only special-cases ERR_MODULE_NOT_FOUND.

Impact: The error path now only special-cases ERR_MODULE_NOT_FOUND. If the circular import manifests as a different Rollup/Vite error code, the original error is rethrown without the new explanation, so users can still get the confusing failure this changeset claims to fix.

Suggested fix: Review the cited evidence, fix the risk if confirmed, and rerun Shipwright.

}
});

test('explains circular imports through $app/env/private', async () => {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shipwright · HIGH

The new test writes a temporary env entry and helper under node_modules/.svelte-kit-env-* inside the real basics app directory.

Impact: The new test writes a temporary env entry and helper under node_modules/.svelte-kit-env-* inside the real basics app directory. If the test fails before the finally block, or if cleanup is interrupted, it leaves generated files in node_modules that could be picked up by other tooling or accidentally committed.

Suggested fix: Review the cited evidence, fix the risk if confirmed, and rerun Shipwright.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant