0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

状況

Svelte でアプリケーション開発を行っている中で次のようなエラーが出ています。

encountered-type-error.png

解決方法

svelte-preprocess を更新しよう!

npm update svelte-preprocess@latest
# or
yarn upgrade svelte-preprocess@latest
package.json (一部抜粋)
"devDependencies": {
  "svelte": "^4.2.18",
  "svelte-check": "^3.8.4",
-  "svelte-preprocess": "^4.10.4",
+  "svelte-preprocess": "^6.0.1",
}

私の場合は上記のようにアップグレードすることで解決しました。

バージョン移行に関して

バージョン更新における移行については下記のリンクを参照して下さい。v3 から v4v5 から v6 への移行について簡潔にまとまっています。

それでもエラーが解決しない!

svelte-preprocess で <script lang=ts> を処理しています。

そのため rollup.config.js または vite.config.jssveltePreprocess を設定できているかを確認してみましょう。以下は設定例です。

rollup.config.js
import svelte from "rollup-plugin-svelte";
import commonjs from '@rollup/plugin-commonjs';
import { sveltePreprocess } from 'svelte-preprocess';

export default {
  plugins: [
    svelte({
      preprocess: sveltePreprocess()
    })
  ]
};
vite.config.js
import { defineConfig } from 'vite';
import { svelte } from '@sveltejs/vite-plugin-svelte';
import { sveltePreprocess } from 'svelte-preprocess';

export default defineConfig({
  plugins: [
    svelte({
      preprocess: sveltePreprocess(),
    }),
  ],
});

そのほか config の詳しい設定方法については Rollup の公式ドキュメントVite の公式ドキュメントを参考にしてください。

Svelte Preprocess とは

PostCSS、SCSS、Less、Stylus、CoffeeScript、TypeScript、Pug などをサポートしているプリプロセッサです。めっちゃ便利!


この記事が役に立ったら 🩷 を頂けると嬉しいです!

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?