Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
pyoner opened this issue May 6, 2019 · 9 comments
Open

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

pyoner opened this issue May 6, 2019 · 9 comments
Labels
bug Something isn't working

Comments

@pyoner
Copy link

pyoner commented May 6, 2019

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
Copy link
Author

pyoner commented May 6, 2019

But it works when svelte installed as a global lib

@jamesbirtles
Copy link
Contributor

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 jamesbirtles added the bug Something isn't working label May 12, 2019
@mikenikles
Copy link

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'

@ghost
Copy link

ghost commented Jul 8, 2020

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
Copy link

ghost commented Jul 19, 2020

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

knightss27 pushed a commit to knightss27/rollup-plugin-mdsvex-pages that referenced this issue Oct 2, 2021
* feat: add mdp-meta pages generation

* fix: svelte dependency

Rollup was throwing an error `[!] Error: Cannot find module 'svelte/compiler'`

(sveltejs/prettier-plugin-svelte#9)

* feat: add date to metadata

* fix: allow dashes in markdown filenames

* fix: typo
@Paultje52
Copy link

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

@nihirv
Copy link

nihirv commented Aug 11, 2023

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

@GetPsyched
Copy link

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!

@naquin
Copy link

naquin commented Sep 11, 2024

Running into this in 2024 still.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

7 participants