darksinge
darksinge3mo ago

Deno compatibility with local Node/NPM package

Hey everyone, I'm hoping to get some configuration advice for a tricky scenario involving Deno compatibility with a local package that targets the npm ecosystem. I’m using a framework called SST, which generates a sidecar package inside an .sst/ directory within my project. The .sst/ directory contains SST’s internal tooling, including its own package.json and node_modules. My Deno code needs to import types from this generated directory. The problem seems rooted in .sst/ targetting the npm ecosystem, but Deno treats .sst/ like any other source code in the project, e.g., expects import foo from 'npm:bar' instead of … from ‘bar’, or import { add } from ‘./calc.ts’ instead of … from ‘./calc’. How do I make Deno treat the sidecar package generated by SST as an npm module? Things I’ve tried: - Configuring the patch field in deno.json . Per the docs, patch is currently limited to JSR packages. - I got type hints working by adding "unstable": ["sloppy-imports"] to deno.json. But, deno check fails with errors like:
error: Relative import path "@pulumi/pulumi" not prefixed with / or ./ or ../ and not in import map from "file:///path/to/project/.sst/platform/src/components/aws/analog.ts"
hint: If you want to use a JSR or npm package, try running 'deno add jsr:@pulumi/pulumi' or 'deno add npm:@pulumi/pulumi'
error: Relative import path "@pulumi/pulumi" not prefixed with / or ./ or ../ and not in import map from "file:///path/to/project/.sst/platform/src/components/aws/analog.ts"
hint: If you want to use a JSR or npm package, try running 'deno add jsr:@pulumi/pulumi' or 'deno add npm:@pulumi/pulumi'
The error message and hint are noted, but as explained above, I don’t believe it’s applicable here because I need Deno to treat .sst/ as an npm module. Note sure if this is relevant, but SST uses Bun as their runtime — not sure if there's an extra compatibility layer to worry about there or not. For a minimal repro, you can run these commands:
deno init sst-deno
cd sst-deno
deno add npm:sst
deno sst init --yes
deno check sst.config.ts
deno init sst-deno
cd sst-deno
deno add npm:sst
deno sst init --yes
deno check sst.config.ts
Thanks for any help you can provide!
5 Replies
marvinh.
marvinh.3mo ago
The patch key has been renamed to links a few versions ago and also supports npm packages maybe you're on an older version of Deno
darksinge
darksingeOP2mo ago
Thanks for the suggestion. I'm using Deno version 2.5.0. I came across the patch field while reading the section on "Modules and dependencies" in the online docs. There's no mention of links, so perhaps the docs are out of date (https://docs.deno.com/runtime/fundamentals/modules/#overriding-local-jsr-packages). I tried using links and got this warning:
❯ deno check --config ./deno.json sst.config.ts
Warning Linked package ignored because package.json was missing version field.
at /xxx/aws-deno/.sst/platform/package.json
❯ deno check --config ./deno.json sst.config.ts
Warning Linked package ignored because package.json was missing version field.
at /xxx/aws-deno/.sst/platform/package.json
The package.json generated by SST does not include a version, so the warning makes sense. I guess .sst/platform isn't technically a NPM package and just targets the Node runtime? Even if I manually add a version, deno check still complains with the usual error of
error: Relative import path "@some-package" not prefixed with / or ./ or ../ and not in import map from "file:///xxx"
error: Relative import path "@some-package" not prefixed with / or ./ or ../ and not in import map from "file:///xxx"
Any other strategies you can think of? Also happy to be pointed to documentation or existing conversations that cover this use case.
Deno
Modules and dependencies
A guide to managing modules and dependencies in Deno. Learn about ECMAScript modules, third-party packages, import maps, dependency management, versioning, and how to publish your own modules.
fry69
fry692mo ago
The first link indeed contains outdated syntax. Here is the canonical link with correct descriptions and explanations -> https://docs.deno.com/runtime/fundamentals/configuration/#overriding-packages
Deno
deno.json and package.json
The guide to configuring your Deno projects. Learn about TypeScript settings, tasks, dependencies, formatting, linting, and how to use both deno.json and/or package.json effectively.
darksinge
darksingeOP2mo ago
As noted in my last response, I tried using links and the issue still persists. Unless I can tell Deno to arbitrarily treat the contents of.sst/ as nodejs code, then I think I'm out of luck. AFAICT, Deno-Node compatibility only works when going through the module system, and Deno complains about .sst/platform/package.json. I'd love for someone to prove me wrong. If I go forward with Deno, I think the solution will be: don't run deno check on anything relying on SST. 🤷‍♂️
marvinh.
marvinh.2mo ago
Can you file an issue for that https://github.com/denoland/deno/issues ? It sounds like something that should work out of the box and that we should fix
GitHub
denoland/deno
A modern runtime for JavaScript and TypeScript. Contribute to denoland/deno development by creating an account on GitHub.

Did you find this page helpful?