{"record":{"id":"6353b6dd00a0ba91","repo":"nats-io/nats-server","slug":"error-setting-up-jetstream-service-imports-for-acc","errorCode":null,"errorMessage":"Error setting up jetstream service imports for account: %v","messagePattern":"Error setting up jetstream service imports for account: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/jetstream.go","lineNumber":812,"sourceCode":"\ta.mu.RLock()\n\ts := a.srv\n\ta.mu.RUnlock()\n\n\tif s == nil {\n\t\treturn fmt.Errorf(\"jetstream account not registered\")\n\t}\n\n\tvar dstAccName string\n\tif sacc := s.SystemAccount(); sacc != nil {\n\t\tdstAccName = sacc.Name\n\t}\n\n\tif !a.serviceImportExists(dstAccName, jsAllAPI) {\n\t\t// Capture si so we can turn on implicit sharing with JetStream layer.\n\t\t// Make sure to set \"to\" otherwise will incur performance slow down.\n\t\tsi, err := a.addServiceImport(s.SystemAccount(), jsAllAPI, jsAllAPI, nil)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"Error setting up jetstream service imports for account: %v\", err)\n\t\t}\n\t\ta.mu.Lock()\n\t\tsi.share = true\n\t\ta.mu.Unlock()\n\t}\n\n\t// Check if we have a Domain specified.\n\t// If so add in a subject mapping that will allow local connected clients to reach us here as well.\n\tif opts := s.getOpts(); opts.JetStreamDomain != _EMPTY_ {\n\t\tmappings := generateJSMappingTable(opts.JetStreamDomain)\n\t\ta.mu.RLock()\n\t\tfor _, m := range a.mappings {\n\t\t\tdelete(mappings, m.src)\n\t\t}\n\t\ta.mu.RUnlock()\n\t\tfor src, dest := range mappings {\n\t\t\tif err := a.AddMapping(src, dest); err != nil {\n\t\t\t\ts.Errorf(\"Error adding JetStream domain mapping: %v\", err)","sourceCodeStart":794,"sourceCodeEnd":830,"githubUrl":"https://github.com/nats-io/nats-server/blob/3a66a489d262bf89b71a71c955c94920394532f3/server/jetstream.go#L794-L830","documentation":"When an account is enabled for JetStream, the server creates a service import from the system account mapping $JS.API (jsAllAPI) into the account. This error wraps any failure from addServiceImport while setting up that import, so the underlying cause (duplicate import, invalid subject, cross-account restriction) is reported as a JetStream setup failure.","triggerScenarios":"Account.EnableJetStream path where a.serviceImportExists(dstAccName, jsAllAPI) is false and a.addServiceImport(s.SystemAccount(), jsAllAPI, jsAllAPI, nil) fails - e.g. an import for that subject already exists pointing elsewhere, or the import conflicts with an export/mapping in the account.","commonSituations":"The account already has a manually configured service import for $JS.API (from JS() in config) that conflicts; account config was applied twice; operator-mode JWT constraints restrict imports; the system account is missing/misconfigured.","solutions":["Inspect the wrapped %v cause in the message to find the underlying addServiceImport failure.","Remove or rename conflicting service imports for the $JS.API subject in the account's configuration.","Let the server manage the JetStream import automatically instead of declaring it manually in config.","Verify a valid system account is configured (SystemAccount option) and reachable.","Retry after resolving; the setup is idempotent when the import already exists."],"exampleFix":"// before (config)\naccounts {\n  JS { imports: [{ stream: { account: SYS, to: \"$JS.API.>\" , prefix: \"JS\" } }] }\n}\n// after\naccounts {\n  JS { jetstream: enable }\n}\n// server creates the $JS.API import itself","handlingStrategy":"try-catch","validationCode":"// Ensure the account does not already declare its own $JS.API service import\nif acc.serviceImportExists(\"$SYS\", \"$JS.API.>\") {\n    return fmt.Errorf(\"remove manual $JS.API import; server creates it automatically\")\n}","typeGuard":null,"tryCatchPattern":"if err := acc.EnableJetStream(limits, tq); err != nil {\n    var cfgErr error\n    if strings.Contains(err.Error(), \"service imports\") {\n        // inspect wrapped cause, fix conflicting import in account config\n    }\n    return err\n}","preventionTips":["Do not hand-configure $JS.API service imports for JetStream-enabled accounts","Use 'jetstream: enable' in account config instead of manual imports","Keep one source of truth for account imports (config OR API, not both)","Read the wrapped %v cause before changing code"],"tags":["jetstream","service-import","nats-server"],"backgroundTag":"jetstream-service-import-failed","analyzedSha":"3a66a489d262bf89b71a71c955c94920394532f3","analyzedAt":"2026-09-02T04:41:54.247Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}