Audrow
Audrow•7mo ago

Error in npm package - how to squelch?

I'm using an npm package that I think isn't being processed for Deno correctly. I get this error:
This expression is not constructable.
Type 'typeof import("file:///Users/audrow/Library/Caches/deno/npm/registry.npmjs.org/sitemapper/3.2.8/sitemapper")' has no construct signatures.deno-ts(2351)
This expression is not constructable.
Type 'typeof import("file:///Users/audrow/Library/Caches/deno/npm/registry.npmjs.org/sitemapper/3.2.8/sitemapper")' has no construct signatures.deno-ts(2351)
I can deno run it and it works fine. But is there a way to remove the error from my editor? Here's a minimal code example. I'm using Deno 1.41.3.
import Sitemapper from 'npm:sitemapper'

const distro = 'rolling'
const url = `https://docs.ros.org/en/${distro}/sitemap.xml`

const sitemap = new Sitemapper();
const {sites} = await sitemap.fetch(url);
console.log(sites);
import Sitemapper from 'npm:sitemapper'

const distro = 'rolling'
const url = `https://docs.ros.org/en/${distro}/sitemap.xml`

const sitemap = new Sitemapper();
const {sites} = await sitemap.fetch(url);
console.log(sites);
1 Reply
Deno AI Helper
Deno AI Helper•7mo ago
The error you're encountering suggests that the npm package sitemapper may not be providing the correct types for Deno's module resolution, specifically the node16 resolution that Deno supports. According to the documentation, many NPM packages fail to correctly provide types under node16 module resolution, which can result in deno check reporting type errors that the TypeScript compiler tsc does not report. To address this issue in your editor, you have a few options: 1. Open an issue at the issue tracker of the sitemapper package about the problem. You could also contribute a fix if you're able to. 2. Use a CDN that rebuilds the packages for Deno support, instead of an npm: identifier. 3. Ignore the type errors in your codebase with // @ts-expect-error or // @ts-ignore. For your specific case, you could try adding // @ts-expect-error above the line where you're getting the error to suppress it in your editor:
import Sitemapper from 'npm:sitemapper'

const distro = 'rolling'
const url = `https://docs.ros.org/en/${distro}/sitemap.xml`

// @ts-expect-error
const sitemap = new Sitemapper();
const { sites } = await sitemap.fetch(url);
console.log(sites);
import Sitemapper from 'npm:sitemapper'

const distro = 'rolling'
const url = `https://docs.ros.org/en/${distro}/sitemap.xml`

// @ts-expect-error
const sitemap = new Sitemapper();
const { sites } = await sitemap.fetch(url);
console.log(sites);
This tells TypeScript to expect an error on the next line and not report it. However, use this with caution as it suppresses the error message, which might hide actual issues with the code. Remember that using // @ts-expect-error or // @ts-ignore is more of a workaround than a solution. If possible, it's better to address the underlying issue with the package's type definitions. 🦕