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

Does not respect default language in svelte.config.js #593

Closed
TheComputerM opened this issue Oct 5, 2020 · 11 comments · Fixed by sveltejs/svelte-preprocess#267
Closed
Labels
question A user question

Comments

@TheComputerM
Copy link

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
@TheComputerM TheComputerM added the bug Something isn't working label Oct 5, 2020
@jasonlyu123
Copy link
Member

Did you restart the language server after altering the config? Because loading config is expensive in terms of performance so we make it only load once.

@TheComputerM
Copy link
Author

yeah, even restarted vs code.

@TheComputerM
Copy link
Author

Read the disclaimer part: https://github.com/sveltejs/svelte-preprocess/blob/master/docs/getting-started.md#31-setting-default-languages

Is this feature planned to be added to the language server?

@jasonlyu123
Copy link
Member

This is supported. Don't know what's causing the problem on your end, Can you provide a minimal reproducible?

@ignatiusmb
Copy link
Member

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

@jasonlyu123
Copy link
Member

Oh yeah. That's the problem. Doesn't notice the mix of common js and es module

@jasonlyu123 jasonlyu123 added question A user question and removed bug Something isn't working labels Oct 6, 2020
@TheComputerM
Copy link
Author

Yeah, I forgot
Will need to fix this

@samal-rasmussen
Copy link
Contributor

samal-rasmussen commented Nov 1, 2020

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.

@jasonlyu123
Copy link
Member

Sorry, the config passed into rollup-plugin-svelte is not visible from the outside of the function.

@nathanblair
Copy link

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)?

@dummdidumm
Copy link
Member

dummdidumm commented 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question A user question
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants