Should not assume package.json is available at CWD
See original GitHub issueHave you read the Contributing Guidelines on issues?
- I have 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:
- Created a year ago
- Comments:7
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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 usingcd docs
βitβs almost always a bad idea to change CWD in the middle of an npm script.@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.