-
Notifications
You must be signed in to change notification settings - Fork 10
Description
Issue
When attempting to use the viewer API installed via NPM with Typescript, the following error is generated:
So what this means is that Typescript is trying to resolve a module in the dir where npm installed Sketchfab - node_modules/@sketchfab/viewer-api/
.
The issue when we take a peek into this dir is how the index file is named:
Testing
Typescript by default looks to resolve modules that match anything similar to: [index.js, index.d.js, index.ts, index.d.ts]
and a few others. You get the point though. When it looks into the Sketchfab dir it doesn't see any JavaScript file that looks like a module export so it ignores it.
To prove this I renamed viewer-api.js
to index.js
:
Then there are no problems:
Resolution
To resolve this, viewer-api.js
should be renamed to index.js
when published so that tooling can more broadly recognize it as a module index.
Workaround
For anyone experiencing this currently, a quick workaround is to alias the Sketchfab index file using Typescript paths:
// tsconfig.json
{
"paths": {
"@sketchfab/my-viewer-api-alias": ["node_modules/@sketchfab/viewer-api/viewer-api.js", // Add this line
}
}
}
You will then be able to import it like so:
import Sketchfab from '@sketchfab/my-viewer-api-alias';