Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Forward slashes not recognised as path on windows #19

Open
Friedpanseller opened this issue Jan 9, 2025 · 0 comments
Open

Forward slashes not recognised as path on windows #19

Friedpanseller opened this issue Jan 9, 2025 · 0 comments

Comments

@Friedpanseller
Copy link

Issue 1

When installed on Windows and started, the console displays:

📦 Creating ...
Error: ENOENT: no such file or directory, mkdir ''
    at Array.map (<anonymous>) {
  errno: -4058,
  code: 'ENOENT',
  syscall: 'mkdir',
  path: ''
}

This is because the path for utilsPath is generated with getDirectoryFromPath(utilsPath) splitting using forward slashes /

const getDirectoryFromPath = (filePath: string) =>
filePath.split('/').slice(0, -1).join('/');

Temporary Fix

In the ./next.config.mjs file manually replace all '\' to '/'

import withRoutes from "@triyanox/next-routes";
import path from "path";
import { cwd } from "process";

/** @type {import('next').NextConfig} */

const nextConfig = withRoutes({
}, {
  utilsPath: path.resolve(cwd(), path.join('lib', 'link$.ts')).replace(/\\/g, "/"),
});

export default nextConfig;

Issue 2

Correct routes are not generated as windows file paths cannot be detected.

The routes here are again detecting forward slashes only so no routes are generated:

const name = routePath.split('/').pop();

As a temporary fix:

  1. replace the line with const name = routePath.split('\\').pop();
  2. In the cleanPath function add .replace(/\\/g, "/") after the appDir replace
const cleanPath = (filePath: string, appDir: string = APP_DIR): string => {
  return filePath
    .replace(appDir, '')
    .replace(/\\/g, "/")
    .replace(/\(.*\)/g, '')
    .replace(/\/$/, '')
    .replace(/^\/\//, '/')
    .replace(/\.[a-z]+$/, '')
    .replace(/\/page$/, '')
    .replace(/\/{2,}/g, '/');
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant