How to Fix: Module parse failed: Bad character escape sequence
This error usually means the shadcn CLI received a malformed registry URL and generated source text containing an invalid escape, which then caused the Next.js build pipeline to stop with Module parse failed: Bad character escape sequence. In the reported reproduction, the command uses a broken URL pattern such as https:/… instead of a valid, fully qualified resource.
Table of Contents
Understanding the Root Cause
The failure happens before your app can run normally. When you execute npx shadcn@latest add with a custom URL, the CLI expects a valid registry endpoint or component source. If that string is malformed, escaped incorrectly, or copied with missing slashes, the generated output can contain characters that JavaScript, TypeScript, JSON, or the bundler interprets as an illegal escape sequence.
In this case, the reproduction shows a suspicious command beginning with https:/…. A valid HTTPS URL must contain two forward slashes after the protocol, like https://. If only one slash is present, downstream tooling may parse the string incorrectly. That bad value can then be written into component code, import paths, config files, or registry metadata, which causes the parser in Webpack, Next.js, or the TypeScript compiler to throw the Bad character escape sequence error.
Another common variation is pasting a Windows-style path, a JSON string with unescaped backslashes, or a custom registry URL that includes characters requiring encoding. Any of these can produce invalid source content during code generation.
Step-by-Step Solution
The fix is to use a valid shadcn component source and then clean any broken generated files before retrying.
1. Recreate or inspect the exact add command
If your command looks like this, it is invalid:
npx shadcn@latest add