Skip to content

Conversation

@Pushkar111
Copy link

@Pushkar111 Pushkar111 commented Dec 13, 2025

Fix: Add npm Scripts for Hardhat Development Workflow

Problem

Running npm run dev fails with "Missing script: 'dev'" because the root package.json has no scripts section.

Current Behavior:

npm run dev
# ❌ Error: Missing script: "dev"

Root Cause:
The scripts section was completely absent from package.json. Hardhat projects traditionally use npx hardhat <command>, but this is not discoverable for contributors expecting a standard npm workflow as documented in the README.

Solution

Added comprehensive scripts section to root package.json with standard Hardhat commands and web frontend shortcuts.

Changes Made

File: package.json (root)

Added Scripts Section

"scripts": {
  "node": "hardhat node",
  "compile": "hardhat compile",
  "test": "hardhat test",
  "test:coverage": "hardhat coverage",
  "clean": "hardhat clean",
  "dev": "hardhat node",
  "web:dev": "cd web && npm run dev",
  "web:build": "cd web && npm run build",
  "web:start": "cd web && npm start",
  "web:lint": "cd web && npm run lint"
}

Available Commands

Hardhat (Blockchain):

  • npm run dev - Start local Hardhat node
  • npm run compile - Compile smart contracts
  • npm test - Run contract tests
  • npm run test:coverage - Generate coverage report
  • npm run clean - Clean build artifacts

Web (Frontend):

  • npm run web:dev - Start Next.js dev server
  • npm run web:build - Build for production
  • npm run web:start - Start production server
  • npm run web:lint - Run ESLint

Key Features

  • npm run dev now works as documented in README
  • ✅ Standard npm workflow for contributors
  • ✅ Clear separation between blockchain and frontend commands
  • ✅ All standard Hardhat commands available
  • ✅ No breaking changes (existing npx hardhat still works)

Testing

Verification

# List all available scripts
npm run

# Output shows all scripts are available:
#   node, compile, test, test:coverage, clean, dev
#   web:dev, web:build, web:start, web:lint

Before Fix

npm run dev
# ❌ Error: Missing script: "dev"

After Fix

npm run dev
# ✅ Started HTTP and WebSocket JSON-RPC server at http://127.0.0.1:8545/

How to Test

# Checkout the branch
git checkout fix/add-hardhat-npm-scripts

# Install dependencies (if needed)
npm install

# Test the dev script
npm run dev
# Should start Hardhat local node

# Test compilation
npm run compile
# Should compile smart contracts

# Test listing scripts
npm run
# Should show all available scripts

Files Changed

package.json
  - Added "scripts" section with 11 commands
  - Total: +13 lines, -1 line

Checklist

  • Code follows existing style and patterns
  • No unrelated files modified
  • Tested npm run dev command
  • Tested npm run to list scripts
  • All scripts follow npm conventions
  • No breaking changes
  • Conventional commit message used

Related Issues

Fixes #100


Ready for review! 🚀

Summary by CodeRabbit

  • Chores
    • Added npm script shortcuts to streamline development workflows, including compilation, testing, coverage, and cleanup utilities.

✏️ Tip: You can customize this high-level summary in your review settings.

- Added standard Hardhat scripts (node, compile, test, clean)
- Added 'dev' script to start local Hardhat node
- Added web frontend shortcuts (web:dev, web:build, web:start, web:lint)
- Enables consistent npm-style workflow for contributors

Fixes StabilityNexus#100
@coderabbitai
Copy link

coderabbitai bot commented Dec 13, 2025

Walkthrough

Added a new scripts section to package.json with npm script shortcuts including dev, compile, test, test:coverage, clean, node, and web variant commands, enabling standard npm-style command execution for project tasks.

Changes

Cohort / File(s) Summary
npm scripts section
package.json
Added top-level scripts object with command mappings for development workflows (dev, test, compile, clean, node, web variants)

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Poem

🐰 Scripts now dance in package.json's song,
npm run dev won't lead devs astray,
No more npx - just shortcuts all day,
Hardhat's hard hat sits snug in the way,
Building with npm has never felt right! 🏗️

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding npm scripts to enable Hardhat development workflow, which is the core objective of this pull request.
Linked Issues check ✅ Passed All coding requirements from issue #100 are met: npm scripts section added to root package.json, dev script now functional, and standard Hardhat commands exposed while maintaining npx compatibility.
Out of Scope Changes check ✅ Passed The pull request contains only the intended changes to package.json adding the scripts section; no unrelated modifications or scope creep detected.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 01b376c and 3b81031.

📒 Files selected for processing (1)
  • package.json (2 hunks)
🔇 Additional comments (1)
package.json (1)

3-14: Well-structured npm scripts section that solves the stated problem.

The scripts section is correctly formatted JSON and provides a clean, discoverable API for contributors to run Hardhat commands and web tasks via standard npm workflows. All Hardhat commands are properly mapped, and the delegation pattern for web scripts is straightforward. The web/ subdirectory's package.json contains all required scripts (dev, build, start, lint), so the web commands will execute correctly.

This resolves the "Missing script: 'dev'" issue and enables the expected npm run dev workflow while preserving backward compatibility with direct npx hardhat invocations.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] - npm run dev fails due to missing npm scripts in Hardhat project

1 participant