I'm working on an SvelteKit project but I'm having difficulties to build a plugin that works on the SSR.
This is the svelte.conf.js file:
import preprocess from 'svelte-preprocess';
import myCustomPlugin from './src/my-custom-plugin.js';
/** @type {import('@sveltejs/kit').Config} */
const config = {
preprocess: preprocess({ postcss: true }),
kit: {
files: { lib: 'src/lib' },
vite: {
build: { ssr: true },
plugins: [myCustomPlugin]
}
}
};
export default config;
And this is the src/my-custom-plugin.js file:
const plugin = {
name: 'my-custom-plugin',
resolveId(file) {
if (file.endsWith('url.ts')) {
throw new Error('FOUND IN RESOLVEID');
}
},
load(file) {
if (file.endsWith('url.ts')) {
throw new Error('FOUND IN LOAD');
}
},
transform(file) {
if (file.endsWith('url.ts')) {
throw new Error('FOUND IN TRANSFORM');
}
}
};
export default plugin;
When I run pnpm svelte-kit build, I get the following error:
vite v2.9.15 building SSR bundle for testing...
✘ [ERROR] No matching export in "src/client.ts" for import "client"
src/url.ts:3:9:
3 │ import { client } from 'src/client';
╵ ~~~~~~
> Build failed with 1 error:
src/url.ts:3:9: ERROR: No matching export in "src/client.ts" for import "client"
src/url.ts:3:9: ERROR: No matching export in "src/client.ts" for import "client"
at failureErrorWithLog (/node_modules/.pnpm/esbuild@0.14.54/node_modules/esbuild/lib/main.js:1624:15)
at /node_modules/.pnpm/esbuild@0.14.54/node_modules/esbuild/lib/main.js:1266:28
at runOnEndCallbacks (/node_modules/.pnpm/esbuild@0.14.54/node_modules/esbuild/lib/main.js:1046:63)
at buildResponseToResult (/node_modules/.pnpm/esbuild@0.14.54/node_modules/esbuild/lib/main.js:1264:7)
at /node_modules/.pnpm/esbuild@0.14.54/node_modules/esbuild/lib/main.js:1377:14
at /node_modules/.pnpm/esbuild@0.14.54/node_modules/esbuild/lib/main.js:678:9
at handleIncomingPacket (/node_modules/.pnpm/esbuild@0.14.54/node_modules/esbuild/lib/main.js:775:9)
at Socket.readFromStdout (/node_modules/.pnpm/esbuild@0.14.54/node_modules/esbuild/lib/main.js:644:7)
at Socket.emit (node:events:527:28)
at Socket.emit (node:domain:475:12)
Which is a fair one because src/client.ts is not exporting a client object. However, this is precisely what I would like to catch with the plugin but, as you can see, the plugin should be raising an error if the file is encountered but no such error is risen which leads to my questions: are the plugins being run in ssr? how can I get the plugins to run?
Many thanks.