You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

NextJS分组路由编译报错:'.既非POSIX也非Windows路径'求助

问题描述

我正在学习NextJS官方课程,创建带括号的(overview)分组路由文件夹后,编译时出现错误:

uncaughtException: Error: . is neither a posix nor a windows path, and there is no 'join' method defined in the file system at join

以下是项目的相关配置信息,请问该问题的成因是什么?

Package.json

{
  "private": true,
  "scripts": {
    "build": "next build",
    "dev": "next dev",
    "start": "next start",
    "seed": "node -r dotenv/config ./scripts/seed.js"
  },
  "dependencies": {
    "@heroicons/react": "^2.0.18",
    "@tailwindcss/forms": "^0.5.6",
    "@types/node": "20.5.7",
    "@vercel/postgres": "^0.5.1",
    "autoprefixer": "10.4.15",
    "bcrypt": "^5.1.1",
    "clsx": "^2.0.0",
    "next": "^14.0.2",
    "postcss": "8.4.31",
    "react": "18.2.0",
    "react-dom": "18.2.0",
    "tailwindcss": "3.3.3",
    "typescript": "5.2.2",
    "zod": "^3.22.2"
  },
  "devDependencies": {
    "@types/bcrypt": "^5.0.1",
    "@types/react": "18.2.21",
    "@types/react-dom": "18.2.14",
    "dotenv": "^16.3.1",
    "eslint": "^8.52.0",
    "eslint-config-next": "^14.0.0",
    "prettier": "^3.0.3"
  },
  "engines": {
    "node": ">=18.17.0"
  }
}

目录结构

  • app
    • (overview)
      • page.tsx
      • loading.tsx
    • customers
      • page.tsx
    • invoices
      • page.tsx
    • layout.tsx

next.config.js

/** @type {import('next').NextConfig} */
const nextConfig = {};

module.exports = nextConfig;
问题成因分析

这个错误的常见成因主要有以下几点:

  • Node.js版本兼容性问题:虽然配置中指定Node.js版本>=18.17.0,但部分18.x版本在路径处理逻辑上可能与Next.js 14.0.2存在冲突。建议升级到Node.js 20.x稳定版本,避免这类路径解析的异常。
  • 依赖包冲突或损坏:项目依赖的包可能存在版本不兼容,或者node_modules文件夹损坏导致路径处理逻辑出错。可以尝试删除node_modules和package-lock.json(或yarn.lock),然后重新执行npm install(或yarn install)来修复。
  • 代码中的路径引用错误:检查(overview)文件夹下的page.tsx和loading.tsx文件,是否存在错误地将.作为路径参数传递给文件系统相关方法(比如fs.join)的情况,这种错误调用会触发路径解析失败。
  • Next.js版本bug:Next.js 14.0.2可能存在与分组路由相关的路径处理bug,尝试升级到最新稳定版,或者降级到14.0.1版本,看是否能解决问题。

内容的提问来源于stack exchange,提问作者Bamboozles83278

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.06 04:46:28