rhysd/remark-emoji

missing type for remark-emoji on ESM ts file

onemen opened this issue · 8 comments

When using import emoji from 'remark-emoji' on .ts file in ESM project with "type": "module",

I get this error:

⚠ Error (TS7016)  | 
Could not find a declaration file for module 
 . c:/projects/_____/node_modules/remark-emoji/index.js implicitly has an 
 type.
   

There are types at c:/projects/_____/node_modules/remark-emoji/types/index.d.ts', but this result could not be resolved when respecting package.json "exports".
The 'remark-emoji library may need to update its package.json or typings.
rhysd commented

I need to understand the reason. I could not find any difference in type definitions configuration in package.json comparing with other packages such as remark-parse.

https://github.com/remarkjs/remark/blob/main/packages/remark-parse/package.json

rhysd commented

Thanks. I could reproduce this with the following tsconfig.json

{
  "compilerOptions": {
    "target": "es2016",
    "module": "NodeNext",
    "esModuleInterop": true,
    "forceConsistentCasingInFileNames": true,
    "strict": true,
    "skipLibCheck": true
  }
}
rhysd commented

It seems that this exports is not correct.

"exports": "./index.js",

I think the following config (or simply removing it) is correct:

  "exports": {
    ".": {
      "import": {
        "types": "./types/index.d.ts",
        "default": "./index.js"
      }
    }
  },
rhysd commented

Released at v3.1.2.

👍

IhToN commented

It seems that this exports is not correct.

"exports": "./index.js",

I think the following config (or simply removing it) is correct:

  "exports": {
    ".": {
      "import": {
        "types": "./types/index.d.ts",
        "default": "./index.js"
      }
    }
  },

This renders the plugin unusable when trying to add it to Storybook:
Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports" main defined in %%REDACTED%%\node_modules\remark-emoji\package.json

The next exports might do the trick, but version 3.1.1 works without any kind of issue:

"exports": {
    ".": {
      "import": {
        "types": "./types/index.d.ts",
        "default": "./index.js"
      },
      "require": "./index.js"
    }
  },

@IhToN same here, made an issue for it: #27