Skip to main content

Fix package repository access failures

Resolve 403 Forbidden errors encountered when installing Midnight packages.

Understanding the error

When installing Midnight packages, the following errors may appear:

npm install @midnight-ntwrk/compact-runtime

npm ERR! code E403
npm ERR! 403 Forbidden - GET https://registry.npmjs.org/@midnight-ntwrk/compact-runtime
npm ERR! 403 In most cases, you or one of your dependencies are requesting
npm ERR! 403 a package version that is forbidden by your security policy

Solution 1: Reset npm registry

The most common cause is an npm configuration pointing to the wrong registry.

1

Check current registry

npm config get registry

If the output differs from https://registry.npmjs.org/, the registry configuration is incorrect.

2

Reset to default registry

npm config set registry https://registry.npmjs.org/
npm config delete @midnight-ntwrk:registry
npm cache clean --force
3

Test installation

npm install @midnight-ntwrk/compact-runtime

Verification: Package installs successfully without errors.

Solution 2: Fix VPN and proxy issues

Corporate VPNs or proxies can block npm access.

1

Disable VPN temporarily

Corporate Networks

On corporate networks, disabling a VPN connection may not be permitted.

Disconnect from the VPN and test:

npm install @midnight-ntwrk/compact-runtime

If the installation succeeds, VPN restrictions are blocking npm access. Configure proxy settings instead.

2

Configure proxy (if VPN is required)

# Set proxy settings
npm config set proxy http://proxy.company.com:8080
npm config set https-proxy http://proxy.company.com:8080

# With authentication
npm config set proxy http://username:password@proxy.company.com:8080
npm config set https-proxy http://username:password@proxy.company.com:8080
3

Test installation

npm install @midnight-ntwrk/compact-runtime

Verification: Package installs successfully through proxy.

Solution 3: Clear configuration and start fresh

Conflicting npm configurations can cause 403 errors. Reset npm to restore defaults.

1

Back up and clear configuration

Important

Back up the npm configuration before clearing it, as this process removes all custom settings.

# Back up existing config
cp ~/.npmrc ~/.npmrc.backup

# Remove all settings
npm config delete registry
npm config delete proxy
npm config delete https-proxy
npm config delete @midnight-ntwrk:registry
2

Set defaults and clean project

Data Loss Warning

The following commands delete node_modules and package-lock.json. Ensure the correct project directory is active before proceeding.

# Set registry
npm config set registry https://registry.npmjs.org/

# Clean project
rm -rf node_modules package-lock.json
npm cache clean --force
3

Test installation

npm install @midnight-ntwrk/compact-runtime

Verification: Package installs successfully.

Platform-specific fixes

# Configure git line endings
git config --global core.autocrlf false

# Use native WSL paths (not /mnt/c/...)
cd /home/yourusername/project

# Clear Windows npm cache
rm -rf /mnt/c/Users/YourName/AppData/Roaming/npm-cache

Quick fix script

Create an automated fix script:

fix-midnight-npm.sh
#!/bin/bash

echo "🔧 Fixing Midnight npm installation..."

# Clear configuration
npm config delete registry
npm config delete @midnight-ntwrk:registry
npm config delete proxy
npm config delete https-proxy

# Set defaults
npm config set registry https://registry.npmjs.org/
npm cache clean --force

# Clean project (only if package.json exists)
if [ -f "package.json" ]; then
echo "📁 Cleaning project files..."
rm -rf node_modules package-lock.json
else
echo "⚠️ No package.json found - skipping project cleanup"
fi

# Test installation
echo "🧪 Testing package installation..."
npm install @midnight-ntwrk/compact-runtime

if [ $? -eq 0 ]; then
echo "✅ Success! Midnight packages are accessible."
else
echo "❌ Installation failed. Try disconnecting from VPN or checking firewall settings."
fi

Run the script:

chmod +x fix-midnight-npm.sh
./fix-midnight-npm.sh

Verify the fix

Confirm that all configurations and installations are functioning correctly:

# Check registry
npm config get registry
# Expected output: https://registry.npmjs.org/

# Test package access
npm view @midnight-ntwrk/compact-runtime
# Expected output: package information

# Verify installation
npm install @midnight-ntwrk/compact-runtime
# Expected result: successful installation

Still not working?

Enable verbose logging

Display detailed error information:

npm install @midnight-ntwrk/compact-runtime --verbose

Common issues include:

  • SSL certificate issues
  • Proxy configuration problems
  • DNS resolution failures
Test direct connection

Verify registry access:

curl https://registry.npmjs.org/@midnight-ntwrk/compact-runtime

A failed request indicates a network connectivity issue.

Next steps

After installation completes successfully, verify the development environment:

# Check installed packages
npm list @midnight-ntwrk

# Verify compiler
compact --version

# Test runtime import
node -e "const runtime = require('@midnight-ntwrk/compact-runtime'); console.log('✅ Runtime loaded');"
Related guides

Install Development Tools

  • Installation guide - Comprehensive setup guide covering the Lace wallet, test tokens, Compact compiler, and proof server installation

  • Build a DApp tutorial - Detailed instructions for installing Node.js, the Compact developer tools, and verifying your installation

  • Install the Compact developer tools - Specific section on installing and managing the Compact compiler toolchain

Configure Your Environment

These guides cover everything from basic prerequisites (Docker, Node.js) to installing the Compact compiler and setting up the proof server for local development.