svelte-persistent-store
svelte-persistent-store copied to clipboard
puzzling issue with svelte/rollup upgrade
Upgrading a some dependencies in a svelte app where this persistent store was working. I haven't pinned down the precise culprit, my hunch/guess is rollup-plugin-node-resolve
"devDependencies": {
"cypress": "^6.2.0",
"npm-run-all": "^4.1.5", -> (removed)
"rollup": "^2.23.1" -> "rollup": "^2.35.1",
"rollup-plugin-commonjs": "^10.1.0", -> "@rollup/plugin-commonjs": "^17.0.0",
"rollup-plugin-node-resolve": "^5.2.0", -> "@rollup/plugin-node-resolve": "^11.0.0",
"rollup-plugin-css-only": "^3.1.0",
"rollup-plugin-livereload": "^1.3.0", -> "rollup-plugin-livereload": "^2.0.0",
"rollup-plugin-svelte": "^5.2.3", -> "rollup-plugin-svelte": "^7.0.0",
"rollup-plugin-terser": "^6.1.0", -> "rollup-plugin-terser": "^7.0.0",
"sirv-cli": "^1.0.8", -> "sirv-cli": "^1.0.10",
"svelte": "^3.29.4" -> "svelte": "^3.31.0"
},
but for some reason I was getting an error at startup.
bundles src/main.ts → public/build/bundle.js...
[!] Error: Could not load /path/to/project/node_modules/svelte-persistent-store/dist/dist/local (imported by src/store.js): ENOENT: no such file or directory, open '/path/to/project/node_modules/svelte-persistent-store/dist/dist/local'
I was able to solve by changing my import from
import { writable } from 'svelte-persistent-store/dist/local';
to
import { writable } from 'svelte-persistent-store/local.js';
Downgrading to @rollup/plugin-node-resolve 10.0 also resolves the issue.
I believe that the rollup plugin behaves correctly because it respects ECMAScript modules. svelte-persitent-store sets the exports field in package.json. When importing the package as an ECMAScript module all paths svelte-persistent-store/foo/bar are rewritten to svelte-persistent-store/dist/foo/bar.
In theory it should now be possible to import from 'svelte-persistent-store/local'. But unfortunately this does not play well with Typescript because the compiler cannot find the types for svelte-persistent-store/local as it looks for ./node_modules/svelte-persistent-store/local.d.ts. A solution could be to include package type declarations in addition to the module type declarations. Alternatively, the dist directory prefix could be removed in the package archive.