LoginSignup
1
0

More than 1 year has passed since last update.

[Vue] <slot> を使うと"TypeError: Cannot read properties of null (reading 'isCE')" になる

Posted at

<slot> を使うとエラーになる

Vue3 で <slot> を使う npm を作成している時のことです。
Vite でコンパイルすると問題ないのに、プロジェクトでその npm を使用すると下記のエラーが出てしまい散々悩まされました。

TypeError: Cannot read properties of null (reading 'isCE')

vite.config.ts の設定

対応方法を検索すると vite.config.tsexternaldedupe を追加しろというものが出てきます。
下記のように追加してみましたがダメでした。

export default defineConfig({
  build: {
    rollupOptions: {
      external: ['vue'],
    },
    // 〜略〜
  },
  resolve: {
    dedupe: ['vue'],
    // 〜略〜
  },
  // 〜略〜
});

結論: npm の中に不要な node_modules を残すな

本来なら npm とプロジェクトは別の場所で開発するものなのですが、今回は手間を省くためにプロジェクトの node_modules 内でそのまま開発していました。

/プロジェクトルート
+-- /src
|   +-- index.ts // ② ここで使う
+-- /node_modules
    +-- /myModule
        +-- /node_modules
        +-- /src
            +-- index.ts // ①ここで npm を開発して

すると Vue パッケージが複数存在することになり、それでエラーになってるようです。

/node_modules/myModule/node_modules を削除したらエラーは出なくなりました。

そもそも vite.config.tsexternaldedupe を指定する理由が Vue パッケージを除外するためですしね。

こんなことで2時間近く悩んでしまった……。

1
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
1
0