Skip to content

adapter-node breaks paths to sourcemap sources by copying files during build #10040

@danieldiekmeier

Description

@danieldiekmeier

Describe the bug

When you turn on sourcemaps in Vite, SvelteKit will generate sourcemaps even for the server. This is great! But during the build, @sveltejs/adapter-node moves the generated files, for example from .svelte-kit/output/server/foo.js to .svelte-kit/adapter-node/foo.js, breaking the relative paths to the sources in the sourcemaps.

This is the code that moves the files:

writeServer(dest) {
return copy(`${config.kit.outDir}/output/server`, dest);
}

I noticed this because I wanted to setup Sentry's new SvelteKit integration, but the sourcemaps would just not work. Sentry is actually using sorcery to try to flatten all the sourcemaps from the different steps of the build: https://github.com/getsentry/sentry-javascript/blob/41fef4b10f3a644179b77985f00f8696c908539f/packages/sveltekit/src/vite/sourceMaps.ts#L136-L139

This almost works, except that adapter-node moves the files, thus breaking the chain.

A fix could be to update the source maps while copying them. (But maybe there are better options.)

Reproduction

Repo: https://github.com/danieldiekmeier/reproduction-adapter-node-sourcemaps

pnpm i
pnpm build
diff .svelte-kit/output/server/chunks/index.js.map .svelte-kit/adapter-node/chunks/index.js.map
# nothing will be printed, which is the problem: it's the same file

Logs

No response

System Info

System:
    OS: macOS 13.3.1
    CPU: (10) arm64 Apple M1 Max
    Memory: 303.64 MB / 64.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 18.13.0 - ~/.asdf/installs/nodejs/18.13.0/bin/node
    Yarn: 1.22.19 - ~/.asdf/installs/nodejs/18.13.0/bin/yarn
    npm: 8.19.3 - ~/.asdf/plugins/nodejs/shims/npm
  Browsers:
    Chrome: 113.0.5672.126
    Edge: 113.0.1774.57
    Firefox: 103.0.2
    Firefox Developer Edition: 113.0
    Safari: 16.4
    Safari Technology Preview: 16.4
  npmPackages:
    @sveltejs/adapter-node: ^1.2.4 => 1.2.4
    @sveltejs/kit: ^1.5.0 => 1.18.0
    svelte: ^3.54.0 => 3.59.1
    vite: ^4.3.0 => 4.3.8

Severity

annoyance

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions