webr icon indicating copy to clipboard operation
webr copied to clipboard

webr type declaration file issue

Open WillemSleegers opened this issue 1 year ago • 6 comments

I get the following warning in VS Code:

Could not find a declaration file for module 'webr'. '/Users/willem/GitHub/distributions-
sampler/node_modules/webr/dist/webr.mjs' implicitly has an 'any' type.
 
There are types at 
'/Users/willem/GitHub/distributions-sampler/node_modules/webr/dist/webR/webr-main.d.ts', 
but this result could not be resolved when respecting package.json "exports". 
The 'webr' library may need to update its package.json or typings.

Should the package.json file be updated?

WillemSleegers avatar Aug 20 '23 09:08 WillemSleegers

Thanks for reporting this, it does look like our package.json needs some work. See also, #250.

georgestagg avatar Aug 21 '23 07:08 georgestagg

I'd love to be able to use this in my own typescript project as well :) I've manually updated the package.json file to:

  "types": "dist/webR/webr-main.d.ts",
  "exports": {
    ".": {
      "node": "./dist/webr.cjs",
      "default": "./dist/webr.mjs",
      "types": "./dist/webR/webr-main.d.ts"
    },

This seems to resolve the issue. This is a temporary solution on my end as I'll have to keep manually patching the package.json file every time it gets reset to the distributed version.

derrickstaten avatar Apr 03 '24 14:04 derrickstaten

Perhaps https://github.com/georgestagg/webr-nextjs-example/blob/main/app/page.tsx#L12-L14 is another workaround for people struggling with this, which doesn't require a change to package.json.

derrickstaten avatar Apr 03 '24 14:04 derrickstaten

Feel free to open a PR with the changes to package.json for your environment. If everything continues to work on my end, I'd be happy to merge the required changes.

georgestagg avatar Apr 03 '24 14:04 georgestagg

I'm not confident that this is the solution yet. Once I am, I will open a PR.

derrickstaten avatar Apr 03 '24 14:04 derrickstaten

I've opened https://github.com/r-wasm/webr/pull/404, as it resolves warnings in a personal project

derrickstaten avatar Apr 05 '24 16:04 derrickstaten