Skip to content

zero-icons scans node_modules causing build failures #3

@sclark-bycore

Description

@sclark-bycore

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:

  1. Create a new project with @react-zero-ui/icon-sprite@0.1.6
  2. Install @hookform/resolvers@^5.2.1 (or any package with decorator syntax in test files)
  3. Add "prebuild": "zero-icons" to package.json scripts
  4. Run npm run prebuild
  5. 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

  1. The scanner should not traverse into node_modules by default
  2. The zero-ui.config.js configuration file should be loaded and respected
  3. Setting ROOT_DIR: 'src' in the config should limit scanning to only the src directory

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions