{"record":{"id":"0420a6aed1d52f74","repo":"laurent22/joplin","slug":"cannot-find-library-library","errorCode":null,"errorMessage":"Cannot find library ${library}","messagePattern":"Cannot find library (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/editor/CodeMirror/pluginApi/codeMirrorRequire.ts","lineNumber":53,"sourceCode":"\t'@lezer/markdown': lezerMarkdown,\n\t'@lezer/highlight': lezerHighlight,\n};\n\nconst codeMirrorRequire = (library: string) => {\n\t// Here, we use hasOwnProperty instead of \"in\" to prevent\n\t// require(\"constructor\") or require(\"__proto__\") from returning\n\t// a constructor or prototype object.\n\tif (libraryNameToPackage.hasOwnProperty(library)) {\n\t\treturn libraryNameToPackage[library];\n\t}\n\n\t// Although window.require doesn't work on mobile, some desktop-only plugins\n\t// originally developed for CodeMirror 5 rely on it.\n\tif (typeof window.require === 'function') {\n\t\treturn window.require(library);\n\t}\n\n\tthrow new Error(`Cannot find library ${library}`);\n};\n\nexport default codeMirrorRequire;\n","sourceCodeStart":35,"sourceCodeEnd":57,"githubUrl":"https://github.com/laurent22/joplin/blob/2654b33620775080d1d59c552259d41e33dad3d2/packages/editor/CodeMirror/pluginApi/codeMirrorRequire.ts#L35-L57","documentation":"Thrown by codeMirrorRequire (the plugin-facing require) when the requested library name is not in the curated libraryNameToPackage whitelist AND window.require is either not a function or also cannot resolve it. The whitelist (lines 22-37) exposes only @codemirror/* and @lezer/* packages so plugins cannot pull arbitrary Node modules or duplicate CodeMirror copies. On mobile window.require is absent, so any non-whitelisted library always fails.","triggerScenarios":"A plugin calls require('codemirror') (the v5 name) which is not whitelisted; require('@codemirror/highlight') which is absent from the map despite being listed in webpack externals (note: the map includes lang-html, lang-markdown, etc. but NOT @codemirror/highlight); require('react') or any third-party module; require misspelled a whitelisted package name.","commonSituations":"CM5 plugin ported to CM6 still calling require('codemirror'); plugin tries to require @codemirror/highlight (present in webpack externals list at line 235 but NOT in the runtime whitelist map at lines 22-37 — a known gap); plugin requires a transitive dependency not exposed by design.","solutions":["Only require packages in the runtime whitelist: @codemirror/{view,state,search,language,autocomplete,commands,lint,lang-html,lang-markdown,language-data} and @lezer/{common,markdown,highlight}.","If you need @codemirror/highlight specifically, note it is missing from the runtime map — file a Joplin issue or use @lezer/highlight instead.","Bundle any other dependency into the plugin's own webpack build instead of require()-ing it at runtime.","Check the exact spelling/version of the package name against the whitelist keys."],"exampleFix":"// before\nconst { EditorView } = require('codemirror');\n// after — use the whitelisted CM6 package name\nconst { EditorView } = require('@codemirror/view');","handlingStrategy":"type-guard","validationCode":"const WHITELIST = new Set([\n  '@codemirror/view','@codemirror/state','@codemirror/search','@codemirror/language',\n  '@codemirror/autocomplete','@codemirror/commands','@codemirror/lint',\n  '@codemirror/lang-html','@codemirror/lang-markdown','@codemirror/language-data',\n  '@lezer/common','@lezer/markdown','@lezer/highlight',\n]);\nfunction safeRequire(name) {\n  if (!WHITELIST.has(name)) throw new Error(`Unsupported require: ${name}`);\n  return require(name);\n}","typeGuard":"function isWhitelistedLibrary(name) {\n  return WHITELIST.has(name);\n}","tryCatchPattern":"try {\n  return codeMirrorRequire(lib);\n} catch (e) {\n  if (/Cannot find library/.test(e.message)) {\n    // bundle the dep into the plugin instead, or suggest an alternative\n  } else throw e;\n}","preventionTips":["Only require the whitelisted @codemirror/* and @lezer/* packages.","Note @codemirror/highlight is in webpack externals but NOT in the runtime whitelist — use @lezer/highlight.","Bundle any other dependency into the plugin's own webpack build."],"tags":["editor","codemirror","plugin","require","dependency"],"backgroundTag":null,"analyzedSha":"2654b33620775080d1d59c552259d41e33dad3d2","analyzedAt":"2026-08-12T14:26:46.263Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}