svelte-preprocess: Svelte-preprocess default option problems
Hello everyone👋🏼 I really love svelte + svelte-preprocess for the ability to use the defaults option.
defaults: {
markup: 'pug',
script: 'coffee',
style: 'sass'
}
But, when I use npm packages (e.g swiper/svelte), I get the error because the npm module is written in html/css/ js by default.
I get this same error when I use svelte-kit. Svelte-kit file generated without defaults and throws an error:
.svelte-kit/dev/generated/root.svelte
How can this problem be avoided? Maybe add option excludePaths? Where path node_modules & .svelte-kit exclude by default?
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 1
- Comments: 20 (10 by maintainers)
Commits related to this issue
- Protocol/SCSS refactoring * Move away from making scss the default, instead specify it manually ("defaults" are now discouraged: https://github.com/sveltejs/svelte-preprocess/issues/362) * Import o... — committed to mozilla/glean-dictionary by wlach 3 years ago
- Protocol/SCSS refactoring * Move away from making scss the default, instead specify it manually ("defaults" are now discouraged: https://github.com/sveltejs/svelte-preprocess/issues/362) * Import o... — committed to mozilla/glean-dictionary by wlach 3 years ago
- Protocol/SCSS refactoring (#973) * Move away from making scss the default, instead specify it manually ("defaults" are now discouraged: https://github.com/sveltejs/svelte-preprocess/issues/362) *... — committed to mozilla/glean-dictionary by wlach 3 years ago
Add
lang=".."to everyscriptorstyletag where it’s needed.The examples are all using rollup. Any idea how the below config can be modified to work with snowpack?. If we remove the defaults and just use
script lang="ts"in all the components, snowpack keeps throwing an “Unexpected token” error. Thanks.module.exports = { preprocess: autoPreprocess({ defaults: { script: "typescript", }, postcss: true, }), };Deprecation notice released in 4.8.0 🎉
@outloudvi Turns out there was just one file that was missing lang=“ts” and causing the build to fail. Your solution helped identify the file and fix the issue. Thanks a ton for the help.
@girishnuli, would you be able to add a line to
node_modules/@snowpack/plugin-svelte/plugin.jsto see which file triggers the error, and potentially have a look at it?(for myself, I realized one file where
lang="ts"is absent in this way.)No, the whole point of the deprecation message is to nudge you into not using it anymore, and there is no replacement, you should do
lang="ts"in each file instead (note: if you have a module script and instance script, they both need that attribute) as this is way more robust for all the tooling out there (except snowpack apparently)Yes, for the Vite issue you need to specify
lang="ts"on every<script>and<script context="module">block because Vite isn’t aware of thedefault. If you still have issues after doing that, please file a new issue with a reproduction in the SvelteKit repo and I’ll take a lookIt turns out this also causes issues with Vite’s
optimizeDeps. SvelteKit forced that off until the latest release (next.146). Now that we’ve allowed it on people’s projects are failing to compile with errors like:Vite only looks at the
scriptblocks and doesn’t try to read thedefault: https://github.com/vitejs/vite/blob/5c0f0a362f669e3d38ddc51bfdd9d424a7c08feb/packages/vite/src/node/optimizer/scan.ts#L32I would really like to be able to set the
defaultand argued in favor of it originally, but it does seem to be causing problems. I think we should either havesvelte-preprocessstart warning or throwing an error ifdefaultis provided to force people off of it or we need to put it somewhere easier for tooling to read like inpackage.jsoninstead ofsvelte.config.jsPutting it in
package.jsonwould fix Problem 1 (https://github.com/sveltejs/svelte-preprocess/pull/350#issuecomment-842906506). I don’t understand Problem 2 and if there’s anything that can fix it including an explicit<script lang="ts">. Perhaps we can discuss this issue more with dummdidumm when he returns from vacationHey, @danitatt 👋 We’re discouraging the usage of the
defaultsoptions since it makes things much harder for tooling, so I’m not sure if adding aexcludePathswould be the correct way forward. Adding an explicitlang=...is the most bug-guaranteed way to use other languages.