Sveltekit $lib is not working within helper function called by Netlify serverless function

Website Draft URL:
Using Sveltekit 1.0 with Netlify-cli 12.9.1

Sveltekit 1.0 now allows us to use a “dynamic” shortcut $lib for the “lib” folder so in code you dont have to be importing from …/…/…/…/lib/ but instead simply use import from $lib/

Im using this a lot in the project Im currently working on and it all works fine locally and deployed. Then I tried changing

import { createClient } from ‘…/…/src/lib/db-helper’;


import { createClient } from ‘$lib/db-helper.js’;

Im using this in all 6 of my netlify functions. Runs fine locally but fails when deployed. So I switch back to …/…/ method and it works fine.

Is this a Sveltekit / Netlify / Adapter-Netlify issue?
Not a biggie - just cant use $lib within helper function called by Netlify functions.

I’m a little confused. Are you using that shortcut inside your SvelteKit code, or your Netlify Functions? If it’s the latter, it’s not supposed to work, at least not till you configure JS or TSConfig.

Sorry for delay in response and confusion. All of my netlify functions contain this line
import { createClient } from ‘…/…/src/lib/db-helper’;

Now, since that db_helper file is within the lib folder, sveltekit allows you to do this instead …
import { createClient } from ‘$lib/db-helper.js’;

(shortens the path). BUT, Netlify doesnt like (understand?) “$lib” when used within Netlify functions, so I have to use the first method shown (…/…/src/lib/ prefix) instead and that runs fine.

Hope thats clearer!

Hi @kreollc,

Thank you for the explanation, but my above statement stands true for your use case:

You’d have to setup your project’s JS/TSConfig to create an alias that points to that directory.

$lib is a Svelte(Kit)-specific alias, which has nothing to do with Netlify.