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.

Does not respect default language in svelte.config.js

See original GitHub issue

Describe the bug My svelte.config.js file looks like this:

import sveltePreprocess from "svelte-preprocess";

module.exports = {
  preprocess: sveltePreprocess({
    defaults: {
      script: "typescript",
      style: "scss",
    },
    postcss: {
      plugins: [require("autoprefixer")()],
    },
  }),
};

Expected behavior It is showing me that you have to add lang='ts' to svelte file that looks something like this:

<script>
  export let segment: string;
</script>

{segment}

Screenshots image

System (please complete the following information):

  • OS: Windows
  • IDE: VSCode
  • Plugin/Package: Svelte for VSCode

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:11 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
dummdidummcommented, Mar 6, 2021

See #509 for more info on this. Also you are allowed to import CommonJS modules from ES modules, you just need to change your file ending to become svelte.config.cjs.

1reaction
nathanblaircommented, Mar 6, 2021

svelte.config.js doesn’t support ES6 import syntax, AFAIK. Try changing the import to

const sveltePreprocess = require('svelte-preprocess');

I tried to reproduce it using your config and it immediately complains with image

The part I was missing was that the svelte language-tools doesn’t read the defaults from the rollup.config.js. I had to add a svelte.config.js file to the root of my project that includes the same config options for sveltePreprocess as in the rollup config.

This is documented in the documentation for svelte-preprocess: https://github.com/sveltejs/svelte-preprocess/blob/master/docs/usage.md#with-svelte-vs-code

Would reading the defaults from the rollup.config.js file be out of the question for the svelte language-tools? Because the onboarding experience for me on this one was a bit painful.

Importing svelte.config.js as an ES6 module should be something that is possible. Not being able to use svelte.config.js so we can have LSP support due to being limited to by CJS is a real pain point in adopting svelte, particularly when the rest of the ecosystem is moving forward with adopting ES6 so everything can stop being so fragmented.

Node recognizes type: "module" from package.json so CJS and module loading at that point become irreconcilable.

What would the blocker be? Is this a LSP issue? Or is it a rollup plugin issue (with the svelte rollup plugin or the svelte-preprocess rollup plugin)?

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Localize a Svelte App with svelte-i18n | Phrase
Arabic is a right-to-left language, and the UI just looks awkward in that locale now. Let's fix this by adding another derived store...
Read more >
Build Setup Recipes
Svelte doesn't build in any opinions on the kind of JavaScript, CSS, or even HTML you write. Therefore, if you want to use...
Read more >
rollup.js
A config file is an ES module that exports a default object with the desired options: export default { input: 'src/main.js', output: {...
Read more >
svelte-preprocess - npm
svelte-vscode needs to know how its (svelte) language server should preprocess your files. This can be achieved by creating a svelte.config.js ...
Read more >
Dynamic behavior in Svelte: working with variables and props
You can also specify a default initial value for a prop. This will be used if the component's consumer doesn't specify the prop...
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