question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Is 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 required 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).

  1. Do we need to have one generate one for Svelte as well?
  2. 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

  1. 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)
  2. Patching the generated .yarn/sdks/typescript/lib/typescript.js (generated via https://yarnpkg.com/getting-started/editor-sdks#vscode) to enable loading svelte-preprocess somehow.

Additional context N/A

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:14 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
TimVoschcommented, Sep 2, 2021

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:

  1. follow yarn pnp instructions (above)
  2. set the typescript resolution for the language-server to typescript 4.3 (shown below)
  3. you might need to run yarn dlx @yarnpkg/sdks vscode again
  4. restart vscode

in your workspace package.json

  "resolutions": {
    "svelte-language-server/typescript": "~4.3",
    "svelte-check/typescript": "~4.3"
  },
2reactions
dsamerottecommented, Feb 21, 2022

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?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found