-
Couldn't load subscription status.
- Fork 3
Description
Describe the bug
The zero-icons scanner recursively scans all directories from the project root, including node_modules, when ROOT_DIR is set to the default empty string (""). This causes build failures when node_modules contain files with syntax that Babel cannot parse (e.g., TypeScript decorators).
Additionally, the config loading functionality in dist/config.js is completely commented out, making it impossible to configure the scanner behavior via zero-ui.config.js.
To Reproduce
Steps to reproduce the behavior:
- Create a new project with
@react-zero-ui/icon-sprite@0.1.6 - Install
@hookform/resolvers@^5.2.1(or any package with decorator syntax in test files) - Add
"prebuild": "zero-icons"to package.json scripts - Run
npm run prebuild - See error:
SyntaxError: Support for the experimental syntax 'decorators' isn't currently enabled
The error occurs because the scanner tries to parse:
node_modules/@hookform/resolvers/class-validator/src/__tests__/Form-native-validation.tsx
Expected behavior
- The scanner should not traverse into
node_modulesby default - The
zero-ui.config.jsconfiguration file should be loaded and respected - Setting
ROOT_DIR: 'src'in the config should limit scanning to only thesrcdirectory
Root Cause
In node_modules/@react-zero-ui/icon-sprite/dist/config.js, lines 2-30 containing the config loading logic are completely commented out, and the hardcoded defaults are used instead:
// All config loading is commented out (lines 2-30)
export const ROOT_DIR = ""; // Default is empty string = scan from project root
In node_modules/@react-zero-ui/icon-sprite/scripts/scan-icons.js, the collect() function recursively scans directories without checking if they should be excluded:
function collect(dir) {
for (const file of fs.readdirSync(dir)) {
const full = path.join(dir, file);
if (fs.statSync(full).isDirectory()) {
collect(full); // No check for node_modules or other directories
continue;
}
// ... parse file
}
}Desktop (please complete the following information):
OS: macOS 15.2 (Darwin 24.6.0)
Node.js: v22.18.0
npm: 10.x
@react-zero-ui/icon-sprite: 0.1.6
Set a sensible default for ROOT_DIR (e.g., "src") instead of ""
Add Babel decorator plugin to the parser config if scanning node_modules is intentional:
presets: [
["@babel/preset-typescript", { isTSX: true, allExtensions: true }],
["@babel/preset-react", { runtime: "automatic" }],
],
plugins: [
["@babel/plugin-proposal-decorators", { legacy: true }]
]
This issue affects any project that:
Has dependencies with decorator syntax in their source/test files
Uses the default configuration
Runs the zero-icons command as part of their build process