Open nhuxhr opened 2 years ago
Are you using pnpm? If yes, possible duplicate of #155
Are you using pnpm? If yes, possible duplicate of #155
Nope! I'm using yarn and the Svelte project is TypeScript.
Exactly the same problem here.
Monorepo with "/studio" and "/web" and the prettier plugin works only if i cd web && code .
I have the same problem
Joining this issue since I have the same problem.
Have a folder with a BE and FE project and just initialized a SvelteKit project inside the FE folder. prettier
doesn't work unless I cd
into the FE folder
Same problem here.
Output logs for Svelte plugin (VSCode opened from /tmp/monorepo
):
Initialize language server at file:///tmp/monorepo
Trying to load configs for /tmp/monorepo
Loaded config at /tmp/monorepo/app/svelte.config.js
...
Error: Cannot find module 'prettier-plugin-svelte'
...
Output logs for Svelte plugin (VSCode opened from /tmp/monorepo/app
):
Initialize language server at file:///tmp/monorepo/app
Trying to load configs for /tmp/monorepo/app
Loaded config at /tmp/monorepo/app/svelte.config.js
One way to resolve this might be to init Svelte language server from the same path as where the svelte.config.js
is located (which would require to change how the language operates, first find config, then init from there).
@jsxclan, @jerebtw, @ItzaMi and @toqueteos, I had some problems in configuring prettier in my monorepo setup. But I fixed them with this setting pluginSearchDirs
. Take a look at my prettier config, which is at the root of the package: apps/client
, hence the value of ../../
, because NPM installed the plugin at the root of the monorepo.
I hope it helps.
/**
* @type {import('prettier').Options}
*/
module.exports = {
plugins: [require('prettier-plugin-tailwindcss')],
pluginSearchDirs: ['.'],
overrides: [{files: '*.svelte', options: {parser: 'svelte'}}],
tailwindConfig: './tailwind.config.cjs',
arrowParens: 'always',
bracketSpacing: false,
endOfLine: 'lf',
plugins: [],
pluginSearchDirs: ['../../'],
printWidth: 80,
semi: true,
singleQuote: true,
tabWidth: 2,
trailingComma: 'es5',
useTabs: false,
svelteSortOrder: 'options-styles-scripts-markup',
svelteStrictMode: true,
svelteBracketNewLine: false,
svelteAllowShorthand: false,
svelteIndentScriptAndStyle: true,
};
@phcoliveira solution didn't work for me but I found a working alternative.
.prettierrc
to prettier.config.cjs
plugins: [require('prettier-plugin-svelte')]
Here's the default .prettierrc
(as generated from npm create svelte@next
) translated into JS:
/**
* @type {import('prettier').Options}
*/
module.exports = {
useTabs: true,
singleQuote: true,
trailingComma: 'none',
printWidth: 100,
plugins: [require('prettier-plugin-svelte')],
pluginSearchDirs: ["."],
overrides: [{ 'files': '*.svelte', 'options': { 'parser': 'svelte' } }]
};
Here's another example of svelte language tools somehow not being able to import modules that are inside a subfolder of the workspace root (the workspace root is ScoringApp-Serverless
; all of the Svelte code and Svelte-related packages are in offline
)
Same problem with this monorepo https://github.com/vercel/turbo/tree/main/examples/with-svelte I used this (https://github.com/sveltejs/prettier-plugin-svelte/issues/311#issuecomment-1320254867) config, but pretttier doesn't look detect svelte files
PS: I manually added file extensions and it works fine
pnpm prettier './**/*.{js,ts,mjs,cjs,json,svelte}' --write
The formatter seems not to be working with monorepo!
I have three mono repo in a project (i.e.
landing
,servers
, andstudio
), thelanding
dir is a Next.js app, while theservers
dir contains multiple servers which are Nest.js apps, and finally, thestudio
dir is a Svelte (SvelteKit) app. If the working directory is the root/project folder prettier works perfectly on thelanding
andservers
dir, and other files in thestudio
dir except for the.svelte
files but the formatter works with.svelte
files if the working directory isstudio
itself.And my PC lag if I have multiple vscode instances running with other heavy applications (i.e. Docker, Firefox, Postman, etc)
What am I doing wrong!?
System info: