You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(build): use __dirname to resolve package.json in postcss.config.js and docsSource/index.js #1929
Both postcss.config.js and docsSource/index.js read package.json with a relative string path:
// postcss.config.js line 2const{homepage, version, author, animateConfig}=JSON.parse(fs.readFileSync('package.json'));// docsSource/index.js line 4const{version}=JSON.parse(fs.readFileSync('package.json'));
In Node.js, fs.readFileSync('package.json') resolves relative to the current working directory (process.cwd()). When PostCSS or the doc generator is invoked from a directory other than the repository root (e.g., cd docsSource && node index.js or cd source && npx postcss animate.css --config ../postcss.config.js), or from a parent monorepo workspace, Node crashes with ENOENT.
Steps To Reproduce
Open a terminal.
Run cd docsSource.
Run node index.js.
See error:
Error: ENOENT: no such file or directory, open '.../docsSource/package.json'
at Object.openSync (node:fs:561:18)
at Object.readFileSync (node:fs:445:35)
at Object.<anonymous> (.../docsSource/index.js:4:33)
### Expected Behavior
Scripts and PostCSS configuration should resolve `package.json` using `path.join(__dirname, ...)` so they can be executed from any working directory.
### Screenshots
_No response_
### Desktop
- OS: Windows, macOS, Linux
- Node Version: v14+ (tested on Node v18, v20, v24)
### Smartphone
_No response_
### Additional Context
**Suggested fix:**
In `postcss.config.js`:
```javascript
const path = require('path');
const {homepage, version, author, animateConfig} = JSON.parse(
fs.readFileSync(path.join(__dirname, 'package.json'))
);
Activity