EDIT: This question is outdated. As of 12.8.2022, svelte-kit package
https://kit.svelte.dev/docs/packaging, is the recommended option.
I created a library (https://github.com/TeemuKoivisto/svelte-tree-view) which I import in another project as a Svelte component. Which works fine linked locally (yarn link svelte-tree-view
) but when I use the npm downloaded version inside my node_modules, I get this extremely weird error:
[!] (plugin svelte) ValidationError: The $ prefix is reserved, and cannot be used for variable and import names
../node_modules/svelte-tree-view/src/TreeView.svelte
77: rootElementStore.set(rootElement);
78: });
79: var $$$$$$$$ = null;
^
80: var $$vars$$ = [$$props, rootElement, $treeStore, treeStore, TreeNode_svelte_1.default];</script>
Which is quite difficult to debug as there isn't much discussion or blog posts out there. Anyway, I surprised myself and finally solved it with a quite simple solution and I want to make this post to help others out there. Here are the most important libraries related to this problem:
"rollup": "^2.56.3",
"rollup-plugin-svelte": "^7.1.0",
"rollup-plugin-ts": "^1.4.2",
"svelte": "^3.42.6",
"svelte-preprocess": "^4.9.4",
"tslib": "^2.3.1",
"typescript": "^4.4.3"