I noticed this issue when 3rd party code slipped into the build of my sveltekit app. I expected production dependencies to be externalized as described here: https://svelte.dev/docs/kit/adapter-node#Deploying
My setup is as follows:
npm install in my-monoreponpm run build in my-sveltekit-appnode ./build in my-sveltekit-appThe app will crash because commonjs code cannot run in an esm environment. This would not be an issue if the package is externalized.
You can inspect the build output of build/server/chunks/hooks.server-*.js and see that the 3rd party code is present here.
Running with vite dev or vite preview works fine as they do not use the output from build/
I created a simple 3rd party package myself (their-cjs-tool) and published it to the Github npm registry.
The node-adapter will mark all direct dependencies of my-sveltekit-app as external, however this does not take into account the dependencies of a linked dependency (my-esm-tool).