sketch-hq/SketchAPI

Error when calling getImportableTextStyleReferencesForDocument

lewishowles opened this issue · 3 comments

I am debugging the reason one of my personal plugins is no longer running after upgrading to Sketch 91.

I have the following simple test running the script runner:

const sketch = require('sketch');
const document = sketch.getSelectedDocument();
const selection = document.selectedLayers;
const UI = require('sketch/ui');

const libraries = require('sketch/dom').getLibraries();
const textStyleLibrary = libraries.find(library => library.id === 'E9851749-CD35-451F-A09D-EB5F97BB217F');
const sharedTextStyleReferences = textStyleLibrary.getImportableTextStyleReferencesForDocument(document);

console.log(sharedTextStyleReferences);

and I'm getting the error

TypeError: MSSharedTextStyleProvider.alloc().initWithDocument is not a function. (In 'MSSharedTextStyleProvider.alloc().initWithDocument(n._getMSDocument())', 'MSSharedTextStyleProvider.alloc().initWithDocument' is undefined)
    at value (/Applications/Sketch.app/Contents/Resources/SketchAPI_dom.js:1:143565)
...

I don't see anything obvious that I'm doing wrong when comparing to the docs - has something changed here? Hopefully it's just something simple.

The 'text style library' I'm selecting by ID contains all of our text styles, which I can see in Components => Text for that file.

Logging the result of that find does show that the correct document is selected, so there are indeed text styles to import.

I have the same issue by calling library.getImportableSymbolReferencesForDocument(document)

Having a similar issue too after updating to v91.

TypeError: MSForeignSymbolProvider.alloc().initWithDocument is not a function.

Sorry about that! This is fixed in Sketch 92 (now in beta https://www.sketch.com/beta/, we’ll release it next week)