question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItΒ collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Should not assume package.json is available at CWD

See original GitHub issue

Have you read the Contributing Guidelines on issues?

Description

I put everything related to docusaurus in the docs folder and level it with package.json, there was no problem before, but recently there was an error.

everything related to the document is in the docs folder, the docs directory structure as follows:

docs      
β”œβ”€β”€ babel.config.js
β”œβ”€β”€ build
β”‚   └── copyTranslations.js
β”œβ”€β”€ docs
β”‚   └── getting-started.md
β”œβ”€β”€ docusaurus.config.js
β”œβ”€β”€ i18n
β”‚   └── zh-cn
β”‚       β”œβ”€β”€ code.json
β”‚       β”œβ”€β”€ docusaurus-plugin-content-blog
β”‚       β”‚   └── options.json
β”‚       β”œβ”€β”€ docusaurus-plugin-content-docs
β”‚       β”‚   β”œβ”€β”€ current
β”‚       β”‚   └── current.json
β”‚       └── docusaurus-theme-classic
β”‚           β”œβ”€β”€ footer.json
β”‚           └── navbar.json
β”œβ”€β”€ sidebars.js
β”œβ”€β”€ src
β”‚   β”œβ”€β”€ css
β”‚   β”‚   └── custom.css
β”‚   β”œβ”€β”€ pages
β”‚   β”‚   β”œβ”€β”€ index.js
β”‚   β”‚   └── index.module.css
β”‚   └── theme
β”‚       └── ReactLiveScope
β”‚           └── index.js
└── static
    └── img
        └── .gitkeep

package.json

{
  "scripts": {
    "docs": "cd docs && docusaurus",
    "docs:dev": "cd docs && docusaurus start",
    "docs:build": "cd docs && docusaurus build",
    "docs:swizzle": "cd docs && docusaurus swizzle",
    "docs:deploy": "cd docs && docusaurus deploy",
    "docs:clear": "cd docs && docusaurus clear",
    "docs:serve": "cd docs && docusaurus serve",
    "docs:write-translations": "cd docs && docusaurus write-translations",
    "docs:write-heading-ids": "cd docs && docusaurus write-heading-ids",
    "docs:copy-translations": "node build/generateExportFile.js"
  },
  "devDependencies": {
    "@docusaurus/core": "2.0.0-beta.15",
    "@docusaurus/preset-classic": "2.0.0-beta.15",
    "@docusaurus/theme-live-codeblock": "^2.0.0-beta.15",
    "docusaurus-plugin-module-alias": "0.0.2",
    "@mdx-js/react": "^1.6.21",
    "clsx": "^1.1.1",
    "prism-react-renderer": "^1.2.1",
    "react": "^17.0.1",
    "react-dom": "^17.0.1",
    "webpack": "^5.61.0",
    "webpack-cli": "^4.3.0"
  }
}

then running the npm run docs:build and other docusaurus-related commands to get an error:

internal/modules/cjs/loader.js:905
  throw err;
  ^

Error: Cannot find module '/Users/jojo/oker/blade/docs/package.json'
Require stack:
- /Users/jojo/oker/blade/node_modules/@docusaurus/core/bin/beforeCli.js
- /Users/jojo/oker/blade/node_modules/@docusaurus/core/bin/docusaurus.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:902:15)
    at Function.Module._load (internal/modules/cjs/loader.js:746:27)
    at Module.require (internal/modules/cjs/loader.js:974:19)
    at require (internal/modules/cjs/helpers.js:93:18)
    at Object.<anonymous> (/Users/jojo/oker/blade/node_modules/@docusaurus/core/bin/beforeCli.js:84:19)
    at Module._compile (internal/modules/cjs/loader.js:1085:14)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
    at Module.load (internal/modules/cjs/loader.js:950:32)
    at Function.Module._load (internal/modules/cjs/loader.js:790:12)
    at Module.require (internal/modules/cjs/loader.js:974:19)
    at require (internal/modules/cjs/helpers.js:93:18)
    at Object.<anonymous> (/Users/jojo/oker/blade/node_modules/@docusaurus/core/bin/docusaurus.js:26:1)
    at Module._compile (internal/modules/cjs/loader.js:1085:14)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
    at Module.load (internal/modules/cjs/loader.js:950:32)
    at Function.Module._load (internal/modules/cjs/loader.js:790:12) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/Users/jojo/oker/blade/node_modules/@docusaurus/core/bin/beforeCli.js',
    '/Users/jojo/oker/blade/node_modules/@docusaurus/core/bin/docusaurus.js'
  ]
}

Self-service

  • I’d be willing to address this documentation request myself.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:7

github_iconTop GitHub Comments

3reactions
Josh-Cenacommented, Apr 12, 2022

This has been brought up in the past, but I didn’t find is severe enough for an immediate fix. The problem is indeed that we assume the package.json file exists at the root of CWD (and site dir, which defaults to CWD, but I can’t remember clearly, it’s all a bit messy). We have multiple places where we make that assumption.

I plan to do a minor refactor regarding importing various JSON modules (mostly package.json) and I’ll take a look at this.

For the time being, please prefer using the siteDir argument instead of using cd docsβ€”it’s almost always a bad idea to change CWD in the middle of an npm script.

yarn start docs
1reaction
Josh-Cenacommented, Apr 13, 2022

@slorber This is the case where a user has a β€œmonorepo-like” FS structure but does not have multiple package.json files. I’ve seen this multiple times, and very often they would use cd in their npm script.

Read more comments on GitHub >

github_iconTop Results From Across the Web

'[Error] Unable to find or read "package.json" in the CWD. The ...
I've been getting this error while trying to create a script file to automate a little of the codePush deployment process. Looking at...
Read more >
Workspaces - npm Docs
You may automate the required steps to define a new workspace using npm init. ... For example, assuming the following structure: . +--...
Read more >
rollup.js
js and webpack, you can use Rollup to compile to UMD or CommonJS format, and then point to that compiled version with the...
Read more >
package.json File – Explained with Examples - CodeSweetly
The package.json 's properties make your project usable to package managers and end-users. Suppose you wish to publish your package to the NPM...
Read more >
Tasks in Visual Studio Code
json file. Note: Task support is only available when working on a workspace folder. It is not available when editing single files. TypeScript...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found