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

Shimmer cannot wrap ESM Modules #27

Open
joelnet opened this issue Jan 3, 2024 · 0 comments · May be fixed by #28
Open

Shimmer cannot wrap ESM Modules #27

joelnet opened this issue Jan 3, 2024 · 0 comments · May be fixed by #28

Comments

@joelnet
Copy link

joelnet commented Jan 3, 2024

When the package.json has type set to module, shimmer is unable to wrap functions.

I don't see a way to monkey patch an ESM project. This may just be limitation of ESM.

Node: 16.19.0, 20.10.0

Error:

/Users/jthoms/dev/shimmer-debug/node_modules/shimmer/index.js:13
  var enumerable = !!obj[name] && obj.propertyIsEnumerable(name)
                                      ^

TypeError: obj.propertyIsEnumerable is not a function
    at defineProperty (/Users/jthoms/dev/shimmer-debug/node_modules/shimmer/index.js:13:39)
    at Function.wrap (/Users/jthoms/dev/shimmer-debug/node_modules/shimmer/index.js:56:3)
    at file:///Users/jthoms/dev/shimmer-debug/src/app.js:4:9
    at ModuleJob.run (node:internal/modules/esm/module_job:193:25)
    at async Promise.all (index 0)
    at async ESMLoader.import (node:internal/modules/esm/loader:530:24)
    at async loadESM (node:internal/process/esm_loader:91:5)
    at async handleMainPromise (node:internal/modules/run_main:65:12)

package.json:

{
  "name": "shimmer-debug",
  "version": "1.0.0",
  "type": "module",
  "scripts": {
    "start": "node app.js"
  },
  "dependencies": {
    "shimmer": "^1.2.1"
  }
}

app.js

import shimmer from "shimmer";
import * as component from "./component.js";

shimmer.wrap(component, "fn", (original) => {
  return function () {
    console.log("!!!!!!!!!!!!!!!!!!!!!");
    return original.apply(this, arguments);
  };
});

component.fn();

component.js

export function fn() {
  console.log("component.fn()");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant