Closed rajbirjohar closed 1 year ago
Is your project a module type (see package.json)?
@pilcrowOnPaper It is. I added "type": "module" to my package.json but then it throws a new error:
TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" for /Users/...repo.../src/index.ts
Edit: Removing it throws the original error up above.
Are you using something like ts-node
?
@pilcrowOnPaper Original I was using nodemon but I tried a clean install using ts-node and both are giving me the same errors. For reference, I followed Fireship's tutorial.
I'm at a loss right now. The starter code on the documentation doesn't exactly help with these sort of obstacles and these issues don't seem to be prevalent with other users.
ts-node
doesn't work with ESM by default. tsconfig.json
:
{
"compilerOptions": {
"module": "ESNext" // or ES2015, ES2020
},
"ts-node": {
"esm": true
}
}
If you use ESM, you also need to explicitly define the fine extension when importing modules:
import auth from "auth/lucia.js"; // yes, .js, not .ts
// ...
Let me try that.
Also, the improved documentation for v2 will be more comprehensive
btw you might need to define the compiler option (updated the original comment)
Do you have an example for a starter repo using the mongoose adapter and typescript? You have one using prisma.
Yeah need to create one, if you're having trouble setting up Express + TypeScript, I could quickly make an example repo?
That would be lovely yes.
https://github.com/pilcrowOnPaper/esm-express-ts
I used tsx
instead of ts-node
since it just works with ESM. I didn't add mongoose
since my experience with that is minimal.
@pilcrowOnPaper You're the best. I will definitely contribute to v2's documentation when I can.
@rajbirjohar Keep in mind that tsx
doesn't do type checking, so for prod builds I recommend running tsc --noEmit
before tsx
. It should be fine for development tho.
@pilcrowOnPaper im using NestJS and it internally uses ts-node with commonJS module. Im getting the same error Error [ERR_REQUIRE_ESM]: require() of ES Module
but i cannot shift to tsx or ESNext as NestJS compiles everything in commonJS.
Package
lucia-auth
Describe the bug
I've tried numerous ways to get this library working with babel, express, and mongoose but I keep getting this error. My code is structured as follows, I created a file containing:
by following the documentation. Then in an API endpoint, I am using it like so:
When I comment out the snippet calling
auth.createUser
, my server runs without any hiccups. The moment I uncomment it, it throws this error:My
tsconfig
is set to use "ESNext".Anyone got any insights at all what could be causing this?