Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ES Module error #52

Closed
wingy3181 opened this issue Jan 20, 2025 · 6 comments · Fixed by #53
Closed

ES Module error #52

wingy3181 opened this issue Jan 20, 2025 · 6 comments · Fixed by #53

Comments

@wingy3181
Copy link

Hi,

I am just trying to run node script.js

with script.js contents as follows:

import CognitoSrpHelper from "cognito-srp-helper";

...

and i get the following output:

$ node aws-incognito-auth.js
node:internal/process/esm_loader:40
      internalBinding('errors').triggerUncaughtException(
                                ^

Error [ERR_UNSUPPORTED_DIR_IMPORT]: Directory import '/project/node_modules/.pnpm/[email protected]/node_modules/buffer/' is not supported resolving ES modules imported from /project/node_modules/.pnpm/[email protected]/node_modules/cognito-srp-helper/dist/esm/index.js
Did you mean to import [email protected]/node_modules/buffer/index.js?
    at finalizeResolution (node:internal/modules/esm/resolve:249:11)
    at moduleResolve (node:internal/modules/esm/resolve:908:10)
    at defaultResolve (node:internal/modules/esm/resolve:1121:11)
    at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:396:12)
    at ModuleLoader.resolve (node:internal/modules/esm/loader:365:25)
    at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:240:38)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:85:39)
    at link (node:internal/modules/esm/module_job:84:36) {
  code: 'ERR_UNSUPPORTED_DIR_IMPORT',
  url: 'file:///project/node_modules/.pnpm/[email protected]/node_modules/buffer/'

Also within the package.json I have set the type: "module"

I noticed in the source code it has the following line

import { Buffer } from "buffer/"; // use the browser compatible buffer library

Obviously there is a reason you are using buffer/....... but how can i get this working then?

@simonmcallister0210
Copy link
Owner

Hey @wingy3181 ,

Having trouble replicating the issue. Could you give me details about your environment? e.g. node version, pnpm version, full package.json, operating system maybe? Anything you can think of

Want to match your environment as closely as possible

@wingy3181
Copy link
Author

wingy3181 commented Jan 25, 2025

Hi @simonmcallister0210

Here is repo where i have the issue in isolation
https://github.com/wingy3181/cognito-srp-helper-issue-52

It has the node version i am using in the .nvmrc file and the pnpm version in the package.json file

My OS is the latest macos 15.2

@simonmcallister0210
Copy link
Owner

Thanks @wingy3181 , I cloned that repo and replicated the bug. Looks like an easy fix

I've published a beta version of the fix under 2.3.3-beta.1. Give it a go a let me know if it fixes the issue. If it does I'll merge the fix a publish

@simonmcallister0210
Copy link
Owner

Oh also.. while I was looking into the issue I noticed the package doesn't have a default export, so I've added that in too

@wingy3181
Copy link
Author

All good @simonmcallister0210
LGTM!
Will let you close the issue when you publish the new version

@simonmcallister0210
Copy link
Owner

Nice, should be published now. Thanks for your help @wingy3181 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants