webr
webr copied to clipboard
webr type declaration file issue
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?
Thanks for reporting this, it does look like our package.json
needs some work. See also, #250.
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.
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.
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.
I'm not confident that this is the solution yet. Once I am, I will open a PR.
I've opened https://github.com/r-wasm/webr/pull/404, as it resolves warnings in a personal project