prettier-plugin-svelte
prettier-plugin-svelte copied to clipboard
Error: Cannot find module 'svelte/compiler' (v 4.2.0)
After update the plugin I got an error "Error: Cannot find module 'svelte/compiler'" I installed the plugin as a global and as a local lib Svelte installed only as a local lib
prettier src/Form.svelte
src/Form.svelte[error] src/Form.svelte: Error: Cannot find module 'svelte/compiler'
[error] at Function.Module._resolveFilename (module.js:547:15)
[error] at Function.Module._load (module.js:474:25)
[error] at Module.require (module.js:596:17)
[error] at require (internal/module.js:11:18)
[error] at Object.parse (/home/jungle/.nvm/versions/node/v8.11.1/lib/node_modules/prettier-plugin-svelte/plugin.js:479:20)
[error] at Object.parse$2 [as parse] (/home/jungle/.nvm/versions/node/v8.11.1/lib/node_modules/prettier/bin-prettier.js:10635:19)
[error] at coreFormat (/home/jungle/.nvm/versions/node/v8.11.1/lib/node_modules/prettier/bin-prettier.js:13844:23)
[error] at format (/home/jungle/.nvm/versions/node/v8.11.1/lib/node_modules/prettier/bin-prettier.js:14103:73)
[error] at formatWithCursor (/home/jungle/.nvm/versions/node/v8.11.1/lib/node_modules/prettier/bin-prettier.js:14119:12)
[error] at Object.formatWithCursor (/home/jungle/.nvm/versions/node/v8.11.1/lib/node_modules/prettier/bin-prettier.js:42520:15)
But it works when svelte
installed as a global lib
As svelte is now a peer dependency you will need svelte installed manually. Looks like maybe prettier picks up the globally installed version of prettier-plugin-svelte which stops us from being able to pick up the locally installed svelte version.
Will probably be able to add something that detects if there is a locally installed version of prettier-plugin-svelte and use that instead
I run into that issue as well, related to a monorepo.
I have prettier installed in the repository root, but the Svelte code is in services/website
. When I run Prettier from the root, e.g. as a pre-commit hook, it fails due to Cannot find module 'svelte/compiler'
Same error in a sapper-template repository.
Run with Gitpod: https://gitpod.io/#https://github.com/crstnio/sapper/pull/1
In console, type: npx prettier --write --plugin-search-dir=. .
... or without --plugin-search-dir
. Same result.
Edit: I don't know what has changed, but after adding some scripts to the PR and noticed that Svelte files were rewritten during prettier:watch
, I tried again with npx prettier --write .
and it works fine now ... See last commit.
I was having the exact same problem, the solution for me was installing svelte as a dependency instead of a peerDependency, after that, prettier cli was working flawlessly
Any updates or a workaround on this issue? I'm also encountring the same problem in a monorepo I'm trying to setup.
@Paultje52 updating the svelte extension in vs code worked for me
I'm facing the same issue. I have tried putting svelte
as dependency
as well as a peerDependency
. Neither fixes this issue. Any help would be appreciated!