Skip to content

Add preprocess to the adapter-static code example #8811

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

Closed
wants to merge 1 commit into from

Conversation

stiegi
Copy link

@stiegi stiegi commented Jan 31, 2023

Without preprocess you get "unexpected token" errors when importing types, as described here: https://stackoverflow.com/questions/72846408/sveltekit-typescript-parse-error-when-importing-types/72846510#72846510

Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.

Tests

  • Run the tests with pnpm test and lint the project with pnpm lint and pnpm check

Changesets

  • If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset by running pnpm changeset and following the prompts. Changesets that add features should be minor and those that fix bugs should be patch. Please prefix changeset messages with feat:, fix:, or chore:.

@changeset-bot
Copy link

changeset-bot bot commented Jan 31, 2023

⚠️ No Changeset found

Latest commit: 3329387

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@@ -14,8 +14,10 @@ Install with `npm i -D @sveltejs/adapter-static`, then add the adapter to your `
// @errors: 2307
/// file: svelte.config.js
import adapter from '@sveltejs/adapter-static';
import preprocess from 'svelte-preprocess';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably should use vitePreprocess here to be in line with the starter template

@gtm-nayan
Copy link
Contributor

Which example are you referring to specifically? I don't think we have any snippet that necessitates a preprocessor on that page.

@eltigerchino
Copy link
Member

https://kit.svelte.dev/docs/adapter-static#usage
This is the page and section referred to.

@dummdidumm
Copy link
Member

I think the problem is that people just copy this verbatim without knowing that they might to adjust things if they are using a preprocessor, and then getting confused by that.
On the other hand, if someone who chose to not use TypeScript at all then they have the reverse problem of svelte-preprocess not being installed, and also being confused. So we either have a short comment there instead like // add preprocessor, if necessary (when you want to use TS, for example), or just leave it be.

@gtm-nayan
Copy link
Contributor

gtm-nayan commented Jan 31, 2023

The example configs differ quite a bit already from what's in the templates, export default config vs export default {, not having the JSDoc etc, and drawing a line for upto where these examples should be copy-pastable isn't easy.

showing a diff would likely be more helpful for highlighting the relevant changes, but even then the snippet says the values there are default options so wouldn't really expect people to be copying it

@stiegi
Copy link
Author

stiegi commented Jan 31, 2023

I think it would be good enough to have a comment that mentions the preprocess.
The problem with this is, for a newcomer, the error message you get will make no sense and it is hard to go from that type error message to the missing preprocessor in the config file. So a hint that specifically targets typescript users might help a lot for newcomers imo

@Rich-Harris
Copy link
Member

Thanks for the PR but I'm against this change — as has been pointed out, it's just as likely that people will add an unwanted preprocessor as that they'll remove one they need. Adding something irrelevant to the code sample just obscures the bit we need to communicate.

If developers blindly copy and paste code, errors like this one will be the least of the problems caused!

We could argue that the error message itself should be more informative in this case, but that's a separate conversation

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

Successfully merging this pull request may close these issues.

5 participants