vercel/next.js · error

Invalid usage of next/script. Did you forget to include a sr

Error message

Invalid usage of next/script. Did you forget to include a src attribute or an inline script? https://nextjs.org/docs/messages/invalid-script

What it means

getPreNextWorkerScripts (Partytown worker script handling in _document) validates each worker-context next/script before embedding: when a script has neither a src prop nor inline content via children or dangerouslySetInnerHTML there is nothing to load, so it throws with this error.

Source

Thrown at packages/next/src/pages/_document.tsx:286

            dangerouslySetInnerHTML &&
            dangerouslySetInnerHTML.__html
          ) {
            // Embed inline script if provided with dangerouslySetInnerHTML
            srcProps.dangerouslySetInnerHTML = {
              __html: dangerouslySetInnerHTML.__html,
            }
          } else if (scriptChildren) {
            // Embed inline script if provided with children
            srcProps.dangerouslySetInnerHTML = {
              __html:
                typeof scriptChildren === 'string'
                  ? scriptChildren
                  : Array.isArray(scriptChildren)
                    ? scriptChildren.join('')
                    : '',
            }
          } else {
            throw new Error(
              'Invalid usage of next/script. Did you forget to include a src attribute or an inline script? https://nextjs.org/docs/messages/invalid-script'
            )
          }

          return (
            <script
              {...srcProps}
              {...scriptProps}
              type="text/partytown"
              key={src || index}
              nonce={props.nonce}
              data-nscript="worker"
              crossOrigin={props.crossOrigin || crossOrigin}
            />
          )
        })}
      </>
    )

View on GitHub (pinned to 0eb3775416)

Solutions

  1. Add a src attribute or inline script content to next/script.
Defensive patterns

Strategy: validation

When it happens

Trigger: next/script is used in _document without src or inline content.

Common situations: A Script tag in pages/_document missing both the src attribute and inline script.


AI-assisted analysis of vercel/next.js@0eb3775416 (2026-08-19). Data as JSON: /api/errors/82c1c532e418c170. Report an issue: GitHub.