prettier-plugin-svelte icon indicating copy to clipboard operation
prettier-plugin-svelte copied to clipboard

Error: Cannot find module 'svelte/compiler' (v 4.2.0)

Open pyoner opened this issue 5 years ago • 9 comments

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)

pyoner avatar May 06 '19 03:05 pyoner

But it works when svelte installed as a global lib

pyoner avatar May 06 '19 03:05 pyoner

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

jamesbirtles avatar May 12 '19 11:05 jamesbirtles

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'

mikenikles avatar Jun 14 '20 14:06 mikenikles

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.

ghost avatar Jul 08 '20 11:07 ghost

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

ghost avatar Jul 19 '20 22:07 ghost

Any updates or a workaround on this issue? I'm also encountring the same problem in a monorepo I'm trying to setup.

Paultje52 avatar Jul 28 '23 02:07 Paultje52

@Paultje52 updating the svelte extension in vs code worked for me

nihirv avatar Aug 11 '23 21:08 nihirv

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!

GetPsyched avatar Sep 30 '23 06:09 GetPsyched