gaurishhs / elysia-session

Sessions plugin for Elysia
MIT License
18 stars 2 forks source link

The current file is a CommonJS module whose imports will produce 'require' calls #5

Closed ultimateshadsform closed 2 weeks ago

ultimateshadsform commented 1 month ago

I don't know what's causing this. image

The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("elysia-session")' call instead.
  To convert this file to an ECMAScript module, change its file extension to '.mts', or add the field `"type": "module"` to 'c:/Users/shadow/Desktop/Coding/shadow-cookie-clicker/server/package.json'.ts(1479)
  import { sessionPlugin } from 'elysia-session';
import { MongooseStore } from './store/session';
import Elysia from 'elysia';
import { client } from './db/db';

new Elysia()
  .use(
    sessionPlugin({
      cookieName: 'session', // Optional, defaults to "session"
      store: new MongooseStore(client!, 'sessions'),
      cookieOptions: {
        httpOnly: true,
        sameSite: 'lax',
        secure: true,
      },
      expireAfter: 15 * 60, // 15 minutes
    })
  )
  .get('/', () => 'Hi')
  .listen(3000);

package.json

{
  "name": "server",
  "version": "1.0.50",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "dev": "bun run --watch src/index.ts"
  },
  "dependencies": {
    "elysia": "^1.1.4",
    "elysia-session": "^0.0.5",
    "mongoose": "^8.5.1"
  },
  "devDependencies": {
    "bun-types": "^1.1.20"
  }
}

tsconfig.json

{
  "compilerOptions": {
    "module": "NodeNext",
    "moduleResolution": "NodeNext",
    "target": "ESNext",
    "resolveJsonModule": true,
    "types": ["bun-types"],
    "esModuleInterop": true,
    "forceConsistentCasingInFileNames": true,
    "strict": true,
    "skipLibCheck": true,
    "baseUrl": ".",
    "paths": {
      "@/*": ["src/*"]
    }
  }
}
ultimateshadsform commented 1 month ago

Nvm had to change from "nodenext" to "node" and it went away.

ultimateshadsform commented 1 month ago

Reopening since that did not fix it. I opened other files and errors all over the place.

gaurishhs commented 1 month ago

Set "type": "module" in package.json

ultimateshadsform commented 2 weeks ago

Set "type": "module" in package.json

Yeah I created a brand new project and everything seems to work as expected! Thank you!