TheBinaryGuy / next-hono-lucia

A Next.js template that uses Hono as the API framework and Lucia for authentication.
MIT License
154 stars 7 forks source link

Cannot find module #2

Closed John-MBDP closed 2 months ago

John-MBDP commented 2 months ago

Description I'm receiving an error about Cannot find module '.src/env/server' when running the pnpm dev command

Steps to Reproduce: Followed the getting started guide to clone the project. I ran the following command:

  1. pnpm install
  2. pnpm db:migrate,
  3. and pnpm dev

image

TheBinaryGuy commented 2 months ago

Thanks for reporting!

If you replace the following in next.config.mjs:

import createJiti from 'jiti';

const jiti = createJiti(new URL(import.meta.url).pathname);

const { serverEnvs } = jiti('./src/env/server');
jiti('./src/env/client');

with this:

import { fileURLToPath } from 'node:url';
import createJiti from 'jiti';

const jiti = createJiti(fileURLToPath(import.meta.url));

const serverEnvPath = './src/env/server';
const clientEnvPath = './src/env/client';

const { serverEnvs } = jiti(serverEnvPath);
jiti(clientEnvPath);

does that work?

John-MBDP commented 2 months ago

Thanks for the prompt response! That did the trick, however, while testing the signup workflow, I am now getting this error.

image

TheBinaryGuy commented 2 months ago

Looks like argon2 is causing some issues.

Question: Did you accidentally remove the webpack stuff from the next config? It should be as following, if not maybe also add serverComponentsExternalPackages to it:

/** @type {import('next').NextConfig} */
const nextConfig = {
    /* ... removed for brevity */
    webpack: config => {
        config.externals.push('@node-rs/argon2', '@node-rs/bcrypt');
        return config;
    },
    experimental: {
        serverComponentsExternalPackages: ['@node-rs/argon2', '@node-rs/bcrypt'],
    },
};

I'll setup a windows VM and test it out today and get back. I'll also setup a windows github workflow so this does not happen moving forward.

John-MBDP commented 2 months ago

I'm so sorry! Yes, I've accidentally removed that portion. Everything is working great :) Thank you for taking the time to make this, the structure is really helpful and the code is well organized.

On an unrelated side note, I came across this template through Reddit and saw you had a discussion with someone about hosting the backend and frontend separately and you mentioned that you’re already using a setup like that for one of your projects. I was wondering if you’d be able to put that into a separate repo. Thanks again!

TheBinaryGuy commented 2 months ago

Thank you! And no worries, I've also updated the repo to ensure that jiti stuff is in place and removed dependency on oslo/password in favor of using @node-rs/argon2 directly. oslo is still there for session expiration but the @node-rs/bcrypt is no longer needed, you can download the new template if you haven't started developing the app yet.

I'll still add a simple test suite that runs on linux and windows as a github workflow so that things like these don't happen in the future. This will also help in adding vitest to this template so folks write tests for their own stuff as well.

Ahh yes, I'm going to upload it tomorrow, and update it in the next week to support workspaces. Just need some time to refactor things that are specific to my project out.

John-MBDP commented 2 months ago

Thank you! looking forward to it. I'm going to close this issue as it has been resolved.