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

Build error The cwd option must be a path to a directory when a file called build exists #9110

Closed
5 of 7 tasks
loopingz opened this issue Jun 29, 2023 · 6 comments · Fixed by #9112
Closed
5 of 7 tasks
Labels
bug An error in the Docusaurus core causing instability or issues with its execution domain: dx Related to developer experience of working on Docusaurus sites good first issue If you are just getting started with Docusaurus, this issue should be a good place to begin.

Comments

@loopingz
Copy link

Have you read the Contributing Guidelines on issues?

Prerequisites

  • I'm using the latest version of Docusaurus.
  • I have tried the npm run clear or yarn clear command.
  • I have tried rm -rf node_modules yarn.lock package-lock.json and re-installing packages.
  • I have tried creating a repro with https://new.docusaurus.io.
  • I have read the console error message carefully (if applicable).

Description

When building docusaurus, it clean the build folder first build

While setting up a Bazel build i had a file called BUILD but as I am on a case-insensitive filesystem, it prevents the folder or got catch in the glob. Creating this error message:

[ERROR] Unable to build website for locale en.
[ERROR] Error: The `cwd` option must be a path to a directory
    at checkCwdOption (/Users/loopingz/Git/docusaurus/private/node_modules/.pnpm/globby@11.1.0/node_modules/globby/index.js:33:9)
    at generateGlobTasks (/Users/loopingz/Git/docusaurus/private/node_modules/.pnpm/globby@11.1.0/node_modules/globby/index.js:42:2)
    at module.exports.sync (/Users/loopingz/Git/docusaurus/private/node_modules/.pnpm/globby@11.1.0/node_modules/globby/index.js:139:20)
    at module.exports.sync (/Users/loopingz/Git/docusaurus/private/node_modules/.pnpm/del@6.1.1/node_modules/del/index.js:119:23)
    at CleanWebpackPlugin.removeFiles (/Users/loopingz/Git/docusaurus/private/node_modules/.pnpm/@docusaurus+core@2.4.1_jgxnvbe4faw3ohf4h6p42qq6oy/node_modules/@docusaurus/core/lib/webpack/plugins/CleanWebpackPlugin.js:136:44)
    at CleanWebpackPlugin.handleInitial (/Users/loopingz/Git/docusaurus/private/node_modules/.pnpm/@docusaurus+core@2.4.1_jgxnvbe4faw3ohf4h6p42qq6oy/node_modules/@docusaurus/core/lib/webpack/plugins/CleanWebpackPlugin.js:93:14)
    at /Users/loopingz/Git/docusaurus/private/node_modules/.pnpm/@docusaurus+core@2.4.1_jgxnvbe4faw3ohf4h6p42qq6oy/node_modules/@docusaurus/core/lib/webpack/plugins/CleanWebpackPlugin.js:73:22
    at Hook.eval [as call] (eval at create (/Users/loopingz/Git/docusaurus/private/node_modules/.pnpm/tapable@2.2.1/node_modules/tapable/lib/HookCodeFactory.js:19:10), <anonymous>:16:1)
    at Hook.CALL_DELEGATE [as _call] (/Users/loopingz/Git/docusaurus/private/node_modules/.pnpm/tapable@2.2.1/node_modules/tapable/lib/Hook.js:14:14)
    at /Users/loopingz/Git/docusaurus/private/node_modules/.pnpm/webpack@5.88.1/node_modules/webpack/lib/Compiler.js:1168:23

I think the error message should be clearer to avoid confusion.

Reproducible demo

No response

Steps to reproduce

  1. Create a new project
  2. Create a file called build in the repository
  3. Launch the build

Expected behavior

Fail with a more human understandable error

Actual behavior

The message displayed is:

[ERROR] Unable to build website for locale en.
[ERROR] Error: The `cwd` option must be a path to a directory
    at checkCwdOption (/Users/loopingz/Git/docusaurus/private/node_modules/.pnpm/globby@11.1.0/node_modules/globby/index.js:33:9)
    at generateGlobTasks (/Users/loopingz/Git/docusaurus/private/node_modules/.pnpm/globby@11.1.0/node_modules/globby/index.js:42:2)
    at module.exports.sync (/Users/loopingz/Git/docusaurus/private/node_modules/.pnpm/globby@11.1.0/node_modules/globby/index.js:139:20)
    at module.exports.sync (/Users/loopingz/Git/docusaurus/private/node_modules/.pnpm/del@6.1.1/node_modules/del/index.js:119:23)
    at CleanWebpackPlugin.removeFiles (/Users/loopingz/Git/docusaurus/private/node_modules/.pnpm/@docusaurus+core@2.4.1_jgxnvbe4faw3ohf4h6p42qq6oy/node_modules/@docusaurus/core/lib/webpack/plugins/CleanWebpackPlugin.js:136:44)
    at CleanWebpackPlugin.handleInitial (/Users/loopingz/Git/docusaurus/private/node_modules/.pnpm/@docusaurus+core@2.4.1_jgxnvbe4faw3ohf4h6p42qq6oy/node_modules/@docusaurus/core/lib/webpack/plugins/CleanWebpackPlugin.js:93:14)
    at /Users/loopingz/Git/docusaurus/private/node_modules/.pnpm/@docusaurus+core@2.4.1_jgxnvbe4faw3ohf4h6p42qq6oy/node_modules/@docusaurus/core/lib/webpack/plugins/CleanWebpackPlugin.js:73:22
    at Hook.eval [as call] (eval at create (/Users/loopingz/Git/docusaurus/private/node_modules/.pnpm/tapable@2.2.1/node_modules/tapable/lib/HookCodeFactory.js:19:10), <anonymous>:16:1)
    at Hook.CALL_DELEGATE [as _call] (/Users/loopingz/Git/docusaurus/private/node_modules/.pnpm/tapable@2.2.1/node_modules/tapable/lib/Hook.js:14:14)
    at /Users/loopingz/Git/docusaurus/private/node_modules/.pnpm/webpack@5.88.1/node_modules/webpack/lib/Compiler.js:1168:23

Your environment

Mac Filesystem with case insensitive filesystem

Self-service

  • I'd be willing to fix this bug myself.
@loopingz loopingz added bug An error in the Docusaurus core causing instability or issues with its execution status: needs triage This issue has not been triaged by maintainers labels Jun 29, 2023
@Josh-Cena Josh-Cena added domain: dx Related to developer experience of working on Docusaurus sites and removed status: needs triage This issue has not been triaged by maintainers labels Jun 29, 2023
@Josh-Cena Josh-Cena changed the title Build error The cwd option must be a path to a directory Build error The cwd option must be a path to a directory when casing doesn't match Jun 29, 2023
@slorber
Copy link
Collaborator

slorber commented Jun 29, 2023

Hey

Thanks for reporting

when casing doesn't match

Does it actually matter? I'm not sure to understand anymore.

The problematic code:

import { sync as delSync } from "del";

const deleted = delSync(patterns, {
  force: false,
  // Change context to build directory
  cwd: this.outputPath,
  dryRun: false,
  dot: true,
  ignore: this.protectWebpackAssets ? this.currentAssets : []
});

Fail with a more human understandable error

How do you see us handle this exactly? What should be the error message?

We can check if this.outputPath is a file (and not a folder) and throw that message, but how do we explain things to the users?

We can also delete the build or BUILD file, but not sure it would be a good idea anyway 🤷‍♂️

@Josh-Cena
Copy link
Collaborator

Mmmm, I may have misread the issue. So it's about a file called build already existing (and nothing to do with the casing, strictly speaking). I think we should throw an error instead of deleting the file.

@Josh-Cena Josh-Cena changed the title Build error The cwd option must be a path to a directory when casing doesn't match Build error The cwd option must be a path to a directory when a file called build exists Jun 29, 2023
@slorber
Copy link
Collaborator

slorber commented Jun 29, 2023

Ah, didn't see you renamed the issue :)

I think we should throw an error instead of deleting the file.

Yes

We could also ignore the deletion error, but not sure it would be a good idea anyway because it could lead to downstream errors due to unability to create the build folder.

➜  Desktop touch build
➜  Desktop mkdir build
mkdir: build: File exists

Marking this as a good first-time contribution, so feel free to send a PR (no need to claim the issue)

Modifications should be done in /packages/docusaurus/src/webpack/plugins/CleanWebpackPlugin.ts

If the this.outputPath file exists (case insensitive, default value is build) we should throw an error and tell the user that Docusaurus needs this folder, or they can choose a different Docusaurus build output dir (CLI docusaurus build --out-dir xyz). We currently don't have any unit tests on this CleanWebpackPlugin so I won't ask for you to take the initiative to start writing them.

@slorber slorber added the good first issue If you are just getting started with Docusaurus, this issue should be a good place to begin. label Jun 29, 2023
@thedevwonder
Copy link
Contributor

I actually found a better method using fs.existsSync() and it works well for a variety of use cases. But it seems the function is restricted to use.

@thedevwonder
Copy link
Contributor

@slorber Sending a PR using fs module #9112. Please let me know if it looks good!

@loopingz
Copy link
Author

Thank you for the quick answer and fix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An error in the Docusaurus core causing instability or issues with its execution domain: dx Related to developer experience of working on Docusaurus sites good first issue If you are just getting started with Docusaurus, this issue should be a good place to begin.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants