Office Add-in Node Debugger
The `office-addin-node-debugger` package facilitates web debugging for Office Add-ins by providing a Node.js instance to act as a proxy for the JavaScript runtime hosted by an Office application. It is a foundational component within the `Office-Addin-Scripts` monorepo, a collection of tools and utilities developed by OfficeDev for Office Add-in projects. While primarily intended as an underlying service, its programmatic interfaces can be imported into Node scripts for custom debugging workflows. The package ships with TypeScript types, promoting robust development. The current stable version is 1.0.6, last published about three months ago, suggesting a maintenance-oriented release cadence as part of a larger toolkit. This package differentiates itself by offering a Node.js-based proxy specific to the Office Add-in ecosystem, enabling integration with VS Code for a streamlined debugging experience, particularly against Edge runtimes.
Common errors
-
Error: Unable to start debugging.
cause This generic error often indicates an underlying issue with the debugging environment setup, such as an invalid manifest path, problems with the development server, or Office application not launching correctly.fixVerify that your add-in manifest path is correct, your development server is running and accessible, and that the specified Office application can be launched and sideloaded. Check logs for more specific errors. -
Port 3000 is already in use.
cause Another application or process is already listening on the specified port, preventing the debugger's development server or proxy from starting.fixChange the port used by your development server or the debugging proxy in your configuration (e.g., `package.json` scripts, `launch.json` in VS Code, or programmatic options). Alternatively, identify and terminate the process currently using the port. -
Cannot find module 'office-addin-node-debugger'
cause The package is not installed or not correctly resolved in your project's `node_modules`. This can happen if `npm install` wasn't run, or if there's an issue with module resolution in a monorepo setup.fixEnsure `office-addin-node-debugger` is listed in your `package.json` dependencies and run `npm install` or `yarn install` in your project root. If in a monorepo, verify workspace configurations. -
Add-in doesn't load in task pane or ribbon customizations are not rendering.
cause This is often related to an invalid or uncacheable add-in manifest, browser caching of static files, or issues with the add-in's web server configuration preventing Office from fetching resources.fixValidate your add-in's manifest (`npx office-addin-manifest validate <manifest-path>`), clear the Office cache and your browser's cache, and ensure your development server is sending appropriate HTTP headers to prevent caching of static assets.
Warnings
- breaking Debugging capabilities for Office Add-ins have seen systematic changes and restrictions across different Office versions and platforms, particularly on Mac App Store versions and newer Outlook for Windows. This can break existing debugging workflows.
- gotcha Outdated add-in manifests or cached files can lead to debugging issues, where changes in your code or manifest are not reflected in the Office application.
- gotcha Using older Node.js versions may lead to compatibility issues with `office-addin-node-debugger` and its dependencies.
- gotcha Debugging tools often require administrative privileges, especially on Windows, for operations like managing certificates or modifying system settings for sideloading and debugging.
- gotcha Port conflicts are common when running local development servers and debugging proxies simultaneously, leading to 'address already in use' errors.
Install
-
npm install office-addin-node-debugger -
yarn add office-addin-node-debugger -
pnpm add office-addin-node-debugger
Imports
- startNodeDebugger
const startNodeDebugger = require('office-addin-node-debugger').startNodeDebugger;import { startNodeDebugger } from 'office-addin-node-debugger'; - stopNodeDebugger
const stopNodeDebugger = require('office-addin-node-debugger').stopNodeDebugger;import { stopNodeDebugger } from 'office-addin-node-debugger'; - NodeDebuggerOptions
import { NodeDebuggerOptions } from 'office-addin-node-debugger'; // Importing type as valueimport type { NodeDebuggerOptions } from 'office-addin-node-debugger';
Quickstart
import { startNodeDebugger, stopNodeDebugger } from 'office-addin-node-debugger';
async function setupAndStartDebugging() {
// In a real scenario, these would come from environment variables or a configuration file.
const manifestPath = process.env.ADDIN_MANIFEST_PATH ?? './manifest.xml';
const devServerPort = parseInt(process.env.DEV_SERVER_PORT ?? '3000');
const debuggerPort = parseInt(process.env.DEBUGGER_PORT ?? '9229');
try {
console.log('Starting Office Add-in Node Debugger...');
const debuggerInstance = await startNodeDebugger({
manifestPath,
devServerPort,
debuggerPort,
verbose: true,
// The 'app' option would typically specify the Office application (e.g., 'excel', 'word').
// For programmatic use, you might need to infer this or provide it based on context.
// app: 'excel',
});
console.log(`Node debugger proxy started on port ${debuggerPort}. Waiting for connection...`);
// Simulate debugging session for a few seconds
await new Promise(resolve => setTimeout(resolve, 15000));
console.log('Stopping Node debugger...');
await stopNodeDebugger(debuggerInstance.pid); // Assuming start returns an object with pid
console.log('Node debugger stopped.');
} catch (error: any) {
console.error('Failed to start or stop node debugger:', error.message);
process.exit(1);
}
}
setupAndStartDebugging();