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

example code process.pwd() path error #43528

Closed
1 task done
xgqfrms opened this issue Nov 29, 2022 · 1 comment
Closed
1 task done

example code process.pwd() path error #43528

xgqfrms opened this issue Nov 29, 2022 · 1 comment

Comments

@xgqfrms
Copy link

xgqfrms commented Nov 29, 2022

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

$ next info
$ npx --no-install next info

$ npx --no-install next info

$ npx --no-install next info 2>&1 | pbcopy

    Operating System:
      Platform: darwin
      Arch: x64
      Version: Darwin Kernel Version 22.1.0: Sun Oct  9 20:14:54 PDT 2022; root:xnu-8792.41.9~2/RELEASE_X86_64
    Binaries:
      Node: 18.12.0
      npm: 8.19.2
      Yarn: 1.22.19
      pnpm: 7.15.0
    Relevant packages:
      next: 13.0.3
      eslint-config-next: 13.0.3
      react: 18.2.0
      react-dom: 18.2.0

warn  - Latest canary version not detected, detected: "13.0.3", newest: "13.0.6-canary.2".
        Please try the latest canary version (`npm install next@canary`) to confirm the issue still exists before creating a new issue.
        Read more - https://nextjs.org/docs/messages/opening-an-issue


Which example does this report relate to?

https://github.com/vercel/next.js/tree/canary/examples/data-fetch

What browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

No response

Describe the Bug

process.pwd() path error

// ./lib/posts.js

const log = console.log;

const __dirname = path.resolve('../posts');
log(`✅ __dirname =`, __dirname);
// ✅ __dirname = /Users/xgqfrms-mm/Documents/github/nextjs-ssr/posts

const cwd = process.cwd();
log(`❌ process.cwd() =`, cwd);
// ❌ process.cwd() = /Users/xgqfrms-mm/Documents/github/nextjs-ssr/lib

const postsDirectory = path.join(process.cwd(), 'posts');
console.log(`❌ postsDirectory =`, postsDirectory);
// ❌ postsDirectory = /Users/xgqfrms-mm/Documents/github/nextjs-ssr/lib/posts

https://nextjs.org/learn/basics/data-fetching/blog-data

$ npx create-next-app@latest nextjs-blog --use-npm --example "https://github.com/vercel/next-learn/tree/master/basics/data-fetching-starter"

https://github.com/vercel/next-learn/tree/master/basics/data-fetching-starter

https://github.com/vercel/next.js/tree/canary/examples/data-fetch

Expected Behavior

right path

// ./lib/posts.js

const log = console.log;

const __dirname = path.resolve('../posts');
log(`✅ __dirname =`, __dirname);
// ✅ __dirname = /Users/xgqfrms-mm/Documents/github/nextjs-ssr/posts

To Reproduce

project tree

$ tree - L 2 - I "node_modules|000-xyz"
  .
├── README.md
├── components
│   ├── footer.js
│   ├── layout.js
│   └── navbar.js
├── next.config.js
├── package - lock.json
├── package.json
├── pages
│   ├── _app.js
│   ├── _document.js
│   ├── api
│   ├── cnblogs
│   ├── index.js
│   └── react_v18
├── posts
│   ├── 2021
│   ├── 2022
│   └── markdown.md
├── public
│   ├── favicon.ico
│   └── vercel.svg
├── styles
│   ├── Home.module.css
│   └── globals.css
└── lib
    ├── parser.js
    ├── posts.js
    └── xyz.js
// ./lib/posts.js

const log = console.log;

const __dirname = path.resolve('../posts');
log(`✅ __dirname =`, __dirname);
// ✅ __dirname = /Users/xgqfrms-mm/Documents/github/nextjs-ssr/posts

const cwd = process.cwd();
log(`❌ process.cwd() =`, cwd);
// ❌ process.cwd() = /Users/xgqfrms-mm/Documents/github/nextjs-ssr/lib

const postsDirectory = path.join(process.cwd(), 'posts');
console.log(`❌ postsDirectory =`, postsDirectory);
// ❌ postsDirectory = /Users/xgqfrms-mm/Documents/github/nextjs-ssr/lib/posts
@xgqfrms xgqfrms added the examples Issue/PR related to examples label Nov 29, 2022
@balazsorban44 balazsorban44 added area: documentation and removed examples Issue/PR related to examples labels Nov 29, 2022
@xgqfrms xgqfrms closed this as completed Nov 30, 2022
@github-actions
Copy link
Contributor

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 31, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants