next-qr
v1.0.2
Published
QR code generator for LAN URLs in Next.js dev server
Downloads
1,202
Maintainers
Readme
next-qr
Print QR codes for your local Next.js dev server so phones and tablets on the same network can open it instantly.
Install
npm install -D next-qrnext >= 12 is required.
Quick Start
next.config.ts
import withQRCode from 'next-qr';
const nextConfig = {
reactStrictMode: true,
};
export default withQRCode(nextConfig);next.config.js / next.config.cjs
const withQRCode = require('next-qr');
module.exports = withQRCode({
reactStrictMode: true,
});Run your dev server as usual:
npm run devWhen the dev server is reachable, next-qr prints LAN URLs and QR codes in the terminal.
CLI
next-qr init
next-qr doctorinit can run from the app directory, a nested folder inside the app, or a workspace root when exactly one Next.js app is found.
Flags:
--skipskips the confirmation prompt--forcere-injectswithQRCode--checkshows planned changes without writing files--quietreduces non-essential output
Bundler Behavior
withQRCode() detects the dev bundler automatically.
It prefers Turbopack when:
bundler: "turbopack"is passed--turbopackor--turbois inprocess.argvnextConfig.turbopackis defined- Next.js major version is
16or newer
It prefers Webpack when:
bundler: "webpack"is passed--webpackis inprocess.argv- the config already has a
webpack(...)function
In Turbopack mode, next-qr waits for the dev server port and then prints QR codes. Serializable options use a detached watcher. Function options such as filter and logger use an in-process watcher instead. If the detached watcher cannot resolve the runtime entry, next-qr falls back to the in-process watcher path.
Options
type NextQRCodePluginOptions = {
bundler?: 'webpack' | 'turbopack' | 'auto';
enabled?: boolean;
port?: number;
path?: string;
protocol?: 'http' | 'https';
once?: boolean;
filter?: (url: string) => boolean;
logger?: {
log: (...args: unknown[]) => void;
warn?: (...args: unknown[]) => void;
};
hostFamily?: 'ipv4' | 'ipv6' | 'all';
includeHosts?: string[];
excludeHosts?: string[];
preferInterface?: string;
startupDelay?: number;
startupTimeout?: number;
};Notes:
enableddisables the integrationoncedefaults totrueonce: falseis supported in Webpack mode; Turbopack still prints once when the dev server becomes reachableportfalls back toprocess.env.PORT, then3000pathis optional and usually stays at the rootprotocoldefaults to"http"and only needs changing for unusual HTTPS dev setupshostFamilydefaults to"ipv4"includeHostsandexcludeHostsmatch raw interface addresses before URLs are builtpreferInterfacechanges ordering and the recommended URLstartupDelayandstartupTimeoutapply only in Turbopack mode
Examples
Force Webpack:
import withQRCode from 'next-qr';
export default withQRCode({}, { bundler: 'webpack' });Filter printed URLs:
import withQRCode from 'next-qr';
export default withQRCode({}, { filter: (url) => url.includes('192.168.') });API
withQRCode(nextConfig, options?)
Wraps a Next.js config and enables QR code printing in development.
new NextQRCodePlugin(options?)
Use the plugin directly if you manage Webpack plugins yourself.
printQRCodes(port, options?)
Prints URLs and QR codes immediately and returns the generated URLs.
getLocalNetworkUrls(port, options?)
Returns LAN URLs without printing anything.
getPreferredNetworkUrl(port, options?)
Returns the first URL after network preference ordering, or null when nothing is reachable.
