postcss-extract-media-query: Fails with ENOENT when getRootPath() returns empty string
When using postcss-extract-media-query@3.1.0 in a build process, the plugin throws an error when attempting to write media query files to a derived output path. The issue occurs because getRootPath() returns an empty string, which results in an invalid write path like /medium.
Error:
☞ write file.../Users/XXXXX/Projects/XXXXXX/wwwb/wwwb-design-package/target/package/jcr_root/apps/wwwb/clientlibs/sass/aemgrid/aemgrid.bundle.css
Waiting for the debugger to disconnect...
node:fs:1364
const result = binding.mkdir(
^
Error: ENOENT: no such file or directory, mkdir '/medium'
at Object.mkdirSync (node:fs:1364:26)
at /Users/XXXXX/Projects/XXXXXX/wwwb/wwwb-design-package/src/main/frontend/node_modules/postcss-extract-media-query/dist/index.js:118:46 {
errno: -2,
code: 'ENOENT',
syscall: 'mkdir',
path: '/medium'
}
Environment: Node.js v22.14.0 macOS Plugin version: 3.1.0
Relevant configuration:
output: {
path: "/Users/XXXXX/Projects/XXXXX/wwwb/wwwb-design-package/target/package/jcr_root/apps/wwwb/clientlibs",
name: '[path]/[query]/[name]-[query].[ext]'
}
Cause:
While debugging, I found that getRootPath(opts.output.path) returns an empty string. As a result, the computed relativePath is also empty, and the plugin ends up trying to write to /medium.
Proposed fix: Replacing this line:
const rootPath = getRootPath(opts.output.path);
With:
const rootPath = getRootPath(opts.output.path) || opts.output.path;
…resolves the issue by falling back to the actual output.path when getRootPath() fails.
Would be great if this fallback could be included in the plugin to avoid the ENOENT error.
Source file structure:
/Users/XXXXX/Projects/XXXXX/wwwb/wwwb-design-package/src/main/frontend/sass/clientlibs/dtcomponents/appstorebuttons/appstorebuttons.clientlibs.scss
Target and expected file structure:
Let me know if the proposed fix makes sense—I’d be happy to open a pull request with the change if it aligns with the intended behavior of the plugin.
Thank you!
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 17 (8 by maintainers)
Glad to hear you’ve got the desired result 😃
Closing as resolved now