{"record":{"id":"8d704797398a1aff","repo":"mobxjs/mobx","slug":"failed-to-find-mobx-import-can-t-add-makeobservab","errorCode":null,"errorMessage":"Failed to find mobx import, can't add makeObservable as dependency in ${fileInfo.path}","messagePattern":"Failed to find mobx import, can't add makeObservable as dependency in (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"packages/mobx-undecorate/src/undecorate.ts","lineNumber":260,"sourceCode":"            createConstructor(clazz, members, privates)\n            needsInitializeImport = true\n        }\n\n        // rewrite all @observer / @inject\n        if (!options?.keepDecorators && decoratorsUsed.has(\"observer\")) {\n            handleObserverAndInject(clazzPath)\n        }\n    })\n\n    if (needsInitializeImport && !options?.ignoreImports) {\n        // @ts-ignore\n        const mobxImport = source\n            .find(j.ImportDeclaration)\n            .filter(im => im.value.source.value === \"mobx\")\n            .nodes()\n            .filter(node => node.importKind === \"value\")[0]\n        if (!mobxImport) {\n            console.warn(\n                \"Failed to find mobx import, can't add makeObservable as dependency in \" +\n                    fileInfo.path\n            )\n        } else {\n            if (!mobxImport.specifiers) {\n                mobxImport.specifiers = []\n            }\n            if (importOverride) {\n                mobxImport.specifiers.push(j.importSpecifier(j.identifier(\"override\")))\n            }\n            mobxImport.specifiers.push(j.importSpecifier(j.identifier(\"makeObservable\")))\n        }\n    }\n    if (!decoratorsUsed.size && !usesDecorate) {\n        return // no mobx in this file\n    }\n    if (changed) {\n        return source.toSource()","sourceCodeStart":242,"sourceCodeEnd":278,"githubUrl":"https://github.com/mobxjs/mobx/blob/01211a698b64ea94de8e5f276ff8235fcf8ddf96/packages/mobx-undecorate/src/undecorate.ts#L242-L278","documentation":"After transforming decorators into `makeObservable` calls, the codemod adds `makeObservable` to the mobx import specifiers. If the file has no value import from 'mobx', it cannot add the dependency and prints a console warning; the generated code may then reference makeObservable without importing it.","triggerScenarios":"Running the codemod on a file whose decorators come from mobx but which lacks `import ... from 'mobx'` (value import) — e.g. the mobx import was removed, aliased differently, or the file relies on a global mobx.","commonSituations":"Files using a custom bundler global injection, incorrect import path (e.g. 'mobx/lib/mobx'), type-only imports (`import type`), or decorators imported from another package re-exporting mobx.","solutions":["Add a value import from 'mobx' to the file before running the codemod: `import { observable } from 'mobx'`.","If you import mobx from an aliased path, temporarily change it to 'mobx' for the codemod run.","After the run, manually add `makeObservable` to the file's imports if the warning appeared."],"exampleFix":"// before\nimport { observable } from 'mobx/lib/mobx'\n// after\nimport { observable, makeObservable } from 'mobx'","handlingStrategy":"validation","validationCode":"if (!/from\\s+['\"]mobx['\"]/.test(src)) {\n  throw new Error(`${file}: add a value import from 'mobx' before running mobx-undecorate`)\n}","typeGuard":"function hasMobxValueImport(source) {\n  return /import\\s+(type\\s*)?\\{[^}]*\\}\\s+from\\s+['\"]mobx['\"]/.test(source) &&\n    !/import\\s+type\\s+\\{[^}]*\\}\\s+from\\s+['\"]mobx['\"]/.test(source)\n}","tryCatchPattern":null,"preventionTips":["Import decorators directly from 'mobx' (not aliased subpaths)","Never rely on globally injected mobx in codemodded files","Check the import list after the codemod run for missing makeObservable"],"tags":["codemod","imports","mobx-undecorate"],"backgroundTag":"missing-import","analyzedSha":"01211a698b64ea94de8e5f276ff8235fcf8ddf96","analyzedAt":"2026-08-28T22:10:08.831Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}