Yarn 2 support
See original GitHub issueIs your feature request related to a problem? Please describe.
The Svelte for VSCode extension cannot currently load modules defined in svelte.config.js
when using Yarn 2. My setup is as follows:
// svelte.config.js
const sveltePreprocess = require('svelte-preprocess');
module.exports = {
preprocess: sveltePreprocess({
defaults: {
script: 'typescript',
},
}),
};
This yields the following error when I open a .svelte file with a <script>
tag:
Error in svelte.config.js
Error: Cannot find module 'svelte-preprocess'
Require stack:
- <project path>/svelte.config.js
- $HOME/.vscode/extensions/svelte.svelte-vscode-102.5.1/node_modules/cosmiconfig/dist/loaders.js
- $HOME/.vscode/extensions/svelte.svelte-vscode-102.5.1/node_modules/cosmiconfig/dist/ExplorerBase.js
- $HOME/.vscode/extensions/svelte.svelte-vscode-102.5.1/node_modules/cosmiconfig/dist/Explorer.js
- $HOME/.vscode/extensions/svelte.svelte-vscode-102.5.1/node_modules/cosmiconfig/dist/index.js
- $HOME/.vscode/extensions/svelte.svelte-vscode-102.5.1/node_modules/svelte-language-server/dist/src/lib/documents/configLoader.js
- $HOME/.vscode/extensions/svelte.svelte-vscode-102.5.1/node_modules/svelte-language-server/dist/src/lib/documents/Document.js
- $HOME/.vscode/extensions/svelte.svelte-vscode-102.5.1/node_modules/svelte-language-server/dist/src/lib/documents/index.js
- $HOME/.vscode/extensions/svelte.svelte-vscode-102.5.1/node_modules/svelte-language-server/dist/src/server.js
- $HOME/.vscode/extensions/svelte.svelte-vscode-102.5.1/node_modules/svelte-language-server/bin/server.jssvelte
My understanding is that the extension needs to be made aware of Yarn’s PnP context to properly load svelte-preprocess
and any other modules require
d in svelte.config.js.
Describe the solution you’d like
With Yarn 2, when one sets up VSCode, some SDKs are generated (for ESlint, Prettier, TypeScript etc).
- Do we need to have one generate one for Svelte as well?
- As part of the setup, one also is advised to update VSCode to use the workspace version of TypeScript. Does the extension automatically pick up the same version or does it need to have it’s own setting as well?
Describe alternatives you’ve considered
- Deleting my
svelte.config.js
file and having the extension use the default settings (use the version of svelte-preprocess that’s bundled with the extension) - Patching the generated
.yarn/sdks/typescript/lib/typescript.js
(generated via https://yarnpkg.com/getting-started/editor-sdks#vscode) to enable loadingsvelte-preprocess
somehow.
Additional context N/A
Issue Analytics
- State:
- Created 3 years ago
- Comments:14 (4 by maintainers)
Top Results From Across the Web
Migration | Yarn - Package Manager
A step-by-step and in-depth migration guide from Yarn 1 (Classic) to Yarn 2 (Berry).
Read more >It's 2021, and You Should Switch to Yarn 2 - Atomic Spin
The list of popular frontend JS tools that natively support PnP is long and growing. 2. Difficulty Migrating from Yarn 1.x. The PnP ......
Read more >Migrating to Yarn 2 - Heroku Dev Center
Heroku users using Yarn are not required to migrate to Yarn 2, and users will have access to Yarn 1 in their apps...
Read more >Migrating our Monorepo to Yarn 2 | DoltHub Blog
How we migrated our monorepo · 1. Install yarn · 2. Add .yarnrc to web · 3. Commit changes and run yarn install...
Read more >Yarn 2 — the future of package managers for JavaScript? - Snyk
Yarn 2 is the new release of the revolutionary and well-established npm package manager Yarn which features improvements, ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Just an FYI for people finding this issue.
The newest version of Typescript (4.4.x) is not compatible with Yarn PnP, but version 4.3.x is compatible through a patch that yarn pnp automatically applies.
Unfortunately(?) svelte-language-server uses the latest typescript by default, breaking yarn pnp support.
As a result, the svelte language server won’t be able to resolve any imports if you’re using yarn pnp in your project.
To fix:
yarn dlx @yarnpkg/sdks vscode
againin your workspace package.json
Has anyone gotten this working? I tried SvelteKit for the first time today but am stuck with the same ERR_MODULE_NOT_FOUND error, an adapter in this case.
I followed the “Getting started” docs, created the demo app, and dropped it into an existing Yarn 3.1.1 (with workspaces) project. The demo runs (although I had to tweak kit.vite.server.fs.allow to serve the demo font from Yarn’s cache), but I can’t get the language server working. I followed the “Usage with Yarn 2 PnP” guide (referenced above) and confirmed the pnpified local version is running, as set in ls-path. I tried downgrading typescript to 4.3.5, per the comment above, although it looks like 4.5.5 should work (i.e., it appears to be patched too). I also tried going from Yarn 3.1.1 to 3.2.0-rc.16, per https://github.com/yarnpkg/berry/issues/3722.
Any other thoughts?