RobbieR
Denoβ€’13mo agoβ€’
1 reply
Robbie

Issues with importing from npm - should I switch to esm.sh?

Is importing from esm.sh recommended over npm? Recently I've been having a lot of issues with imports from npm inside Jupyter. For example:

import * as crypto from "node:crypto";
import { DynamoDB } from "npm:@aws-sdk/client-dynamodb@3.714.0";


results in an error:

Stack trace:
Error: Cannot find module '@aws-sdk/credential-provider-node'
Require stack:
- /Users/robbie/Library/Caches/deno/npm/registry.npmjs.org/@aws-sdk/client-dynamodb/3.714.0_1/dist-cjs/runtimeConfig.js
- /Users/robbie/Library/Caches/deno/npm/registry.npmjs.org/@aws-sdk/client-dynamodb/3.714.0_1/dist-cjs/index.js
- /Users/robbie/Library/Caches/deno/npm/registry.npmjs.org/@aws-sdk/client-dynamodb/3.714.0_1/dist-cjs/index.js
    at Function.Module._resolveFilename (node:module:619:15)
    at Function.Module._load (node:module:497:27)
    at Module.require (node:module:681:19)
    at require (node:module:812:16)
    at Object.<anonymous> (file:///Users/robbie/Library/Caches/deno/npm/registry.npmjs.org/@aws-sdk/client-dynamodb/3.714.0_1/dist-cjs/runtimeConfig.js:58:4)
    at Module._compile (node:module:745:34)
    at loadMaybeCjs (node:module:770:10)
    at Object.Module._extensions..js (node:module:755:12)
    at Module.load (node:module:662:32)


and

import * as crypto from "node:crypto";
import { DynamoDB } from "npm:@aws-sdk/client-dynamodb@3.714.0";
import { DynamoDBDocument } from "npm:@aws-sdk/lib-dynamodb@3.431.0";


results in a different error:

Stack trace:
TypeError: [ERR_MODULE_NOT_FOUND] Cannot find module 'file:///Users/robbie/Library/Caches/deno/npm/registry.npmjs.org/@aws-sdk/client-dynamodb/3.714.0_2/index.js' imported from 'file:///Users/robbie/Developer/iyield/$deno$repl.mts'
    at async <anonymous>:2:22


If I switch to:

import * as crypto from "node:crypto";
import { DynamoDB } from "https://esm.sh/@aws-sdk/client-dynamodb@3.714.0";
import { DynamoDBDocument } from "https://esm.sh/@aws-sdk/lib-dynamodb@3.714.0";


The errors go away.
Was this page helpful?