staytuned_teamS
Deno11mo ago
6 replies
staytuned_team

Resolving Dependencies for Local ESM NPM Packages in Deno

Hi Deno Community,
I'm seeking guidance on the best approach for a setup involving a Deno application and a local, unpublished npm package using ESM. I'm having trouble with Deno automatically resolving the npm package's dependencies without explicit declarations in Deno's config file.
Here's the project structure:
local_module/
├── package1/         (NodeJS package using CJS)
│   ├── index.js
│   └── package.json
│   └── package-lock.json
├── package2/         (NPM package using ESM)
│   ├── dist/
│   │   └── index.js
│   ├── src/
│   │   └── index.ts
│   ├── package.json
│   ├── package-lock.json
│   └── tsconfig.json
└── deno-app/          (The Main Deno Application)
    ├── main.ts
    └── deno.json

package2 Structure:


* package2/src/index.ts:

    import { v4 as uuidv4 } from 'uuid';
    import { marked } from 'marked';

    function hello(): string {
        return "Hello from package 2 !" + uuidv4();
    }

    function processText(text: string){
        const upper = text.toUpperCase();
        return marked.parse(upper);
    }

    export { hello, processText };


* package2/package.json:

    {
      "name": "package2",
      "version": "1.0.0",
      "type": "module",
      "main": "dist/index.js",
      "scripts": {
        "build": "tsc"
      },
      "dependencies": {
        "lodash": "^4.17.21",
        "marked": "^15.0.6",
        "uuid": "^11.0.5"
      },
      "devDependencies": {
        "@types/node": "^22.12.0",
        "typescript": "^5.7.3"
      }
    }


* deno-app/main.ts:

    import * as p2 from "package2";

    console.log(p2.hello());
    console.log(p2.processText("test string to process"));


* deno-app/deno.json:

    {
        "imports": {
            "package2": "../package2/dist/index.js",
        },
        "tasks": {
            "run" : "deno run --allow-read main.ts "
        }
    }
Was this page helpful?