Skip to content

Types break with moduleResolution NodeNext in tsconfig.json #366

@unshame

Description

@unshame

With "moduleResolution": "NodeNext" in tsconfig.json, typescript incorrectly assumes the type of exports of @tinymce/tinymce-vue.

This works at runtime but doesn't compile:

<script setup lang="ts">
import Editor from '@tinymce/tinymce-vue';
</script>

<template>
    <Editor /> 
    <!-- Type '{}' is not assignable to type 'ComponentProps<typeof import("node_modules/@tinymce/tinymce-vue/lib/cjs/main/ts/index")>' -->
</template>

This compiles but breaks at runtime:

<script setup lang="ts">
import EditorImport from '@tinymce/tinymce-vue';

const Editor = EditorImport.default;
</script>

<template>
    <Editor />
</template>

This works, but requires a dynamic import:

<script setup lang="ts">
const Editor = defineAsyncComponent(async () => (await import('@tinymce/tinymce-vue')).default);
</script>

<template>
    <Editor />
</template>

The way I managed to fix it is to patch @tinymce/tinymce-vue's package.json with "type": "module", so typescript knows to treat it as an es module. But I'm not sure if that's a proper solution, since I'm still trying to wrap my head around this whole typescript node esm disaster.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions