#Server-only modules for Nitro

3 messages · Page 1 of 1 (latest)

neon walrus
#

Hello all. I'm just starting to work with nuxt...I got a basic app running, and then added some modules in the server/ directory to interface with my existing SQL Server database in order to implement logins and sessions.

However, this seems to have broken nuxt.

I'm seeing in the browser devtools console that nuxt is trying to load all my server/lib/db files and choking on the node-mssql library. I thought everything in the server/ directory was server-only, but apparently not...

What is the preferred method for adding modules for use only in the server side api handlers so it won't try to load them on the client?

Thanks!

sly epoch
neon walrus
#

Ok, I figured it out...
Just forgot how I initially set up the code on the client side of the login before I implemented the server side...
Turns out I was defining and exporting my User type (needed on client side) in the same module where I eventually defined the db functions (createUser, getUserByUsername, etc...)

So on the client side I was using:
import type { User } from '~/lib/types'
but types.ts had:

export type { User }```
and in users.ts:
```import sql from 'mssql'```

...so the client now needed to load mssql 😱