Skip to content
This repository has been archived by the owner on Sep 27, 2024. It is now read-only.

Importing @matrix-org/matrix-wysiwyg with esm + typescript results in error due to exports in package.json #976

Open
MTRNord opened this issue May 12, 2024 · 1 comment

Comments

@MTRNord
Copy link

MTRNord commented May 12, 2024

Problem

TSC spits out this error for any import:

error TS7016: Could not find a declaration file for module '@matrix-org/matrix-wysiwyg'. '<redacted>/node_modules/@matrix-org/matrix-wysiwyg/dist/matrix-wysiwyg.js' implicitly has an 'any' type.
  There are types at '<redacted>/node_modules/@matrix-org/matrix-wysiwyg/dist/index.d.ts', but this result could not be resolved when respecting package.json "exports". The '@matrix-org/matrix-wysiwyg' library may need to update its package.json or typings.

Steps to reproduce

Import the package in an esm module project with these compilerOptions (these are somewhat vitejs as an origin):

    "compilerOptions": {
        "experimentalDecorators": false,
        "emitDecoratorMetadata": false,
        "resolveJsonModule": true,
        "esModuleInterop": true,
        "module": "es2022",
        "moduleResolution": "Bundler",
        "target": "es2020",
        "noUnusedLocals": true,
        "sourceMap": false,
        "outDir": "./lib",
        "declaration": true,
        "jsx": "react",
        "lib": ["es2021", "dom", "dom.iterable"],
        "strict": true,
        "allowImportingTsExtensions": true,
        "isolatedModules": true,
        "noEmit": true,
    },
@MTRNord
Copy link
Author

MTRNord commented May 12, 2024

It seems like this export declaration makes tsc happy:

"exports": {
        ".": {
            "import": {
                "types": "./dist/index.d.ts",
                "default": "./dist/matrix-wysiwyg.js"
            },
            "require": {
                "types": "./dist/index.d.ts",
                "default": "./dist/matrix-wysiwyg.umd.cjs"
            }
        }
    },

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

No branches or pull requests

1 participant