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

Getting "Cannot read property 'value' of undefined" when using aspect.js from Node.js 10.12.0, plain JavaScript project that uses Babel 7 #71

Closed
matthewadams opened this issue Nov 11, 2018 · 2 comments

Comments

@matthewadams
Copy link
Collaborator

aspect.js is broken when using Node.js in a plain JavaScript project that uses Babel 7; error is below. Babel settings are in the babel section of the package.json. I have a feeling that the issue is related to @babel/plugin-proposal-decorators.

A git repository with reproducible test case is at https://github.com/matthewadams/aspect.js-babel7-poc. You can reproduce the error by cloning the repo and issuing the following command:

npm test

The same error exists when using Node.js 8.12.0.

I'm getting the following error:

/Users/matthewadams/dev/aspect.js-babel7-poc/node_modules/aspect.js/src/join_points/static_method.js:61
            pointcut.advice = new constr(target, descriptor.value);
                                                            ^

TypeError: Cannot read property 'value' of undefined
    at /Users/matthewadams/dev/aspect.js-babel7-poc/node_modules/aspect.js/src/join_points/static_method.js:61:61
    at _decorateElement (/Users/matthewadams/dev/aspect.js-babel7-poc/lib/main/aspects/Aspect.js:1:45845)
    at /Users/matthewadams/dev/aspect.js-babel7-poc/lib/main/aspects/Aspect.js:1:44152
    at Array.forEach (<anonymous>)
    at _decorateClass (/Users/matthewadams/dev/aspect.js-babel7-poc/lib/main/aspects/Aspect.js:1:43891)
    at _decorate (/Users/matthewadams/dev/aspect.js-babel7-poc/lib/main/aspects/Aspect.js:1:37108)
    at Object.<anonymous> (/Users/matthewadams/dev/aspect.js-babel7-poc/lib/main/aspects/Aspect.js:2:112)
    at Module._compile (internal/modules/cjs/loader.js:688:30)
    at Module.replacementCompile (/Users/matthewadams/dev/aspect.js-babel7-poc/node_modules/nyc/node_modules/append-transform/index.js:58:13)
    at Module._compile (/Users/matthewadams/dev/aspect.js-babel7-poc/node_modules/pirates/lib/index.js:83:24)
    at Module._extensions..js (internal/modules/cjs/loader.js:699:10)
    at /Users/matthewadams/dev/aspect.js-babel7-poc/node_modules/nyc/node_modules/append-transform/index.js:62:4
    at newLoader (/Users/matthewadams/dev/aspect.js-babel7-poc/node_modules/pirates/lib/index.js:88:7)
    at Object.<anonymous> (/Users/matthewadams/dev/aspect.js-babel7-poc/node_modules/nyc/node_modules/append-transform/index.js:62:4)
    at Module.load (internal/modules/cjs/loader.js:598:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
    at Function.Module._load (internal/modules/cjs/loader.js:529:3)
    at Module.require (internal/modules/cjs/loader.js:636:17)
    at require (internal/modules/cjs/helpers.js:20:18)
    at Object.<anonymous> (/Users/matthewadams/dev/aspect.js-babel7-poc/lib/main/Thing.js:1:56820)
    at Module._compile (internal/modules/cjs/loader.js:688:30)
    at Module.replacementCompile (/Users/matthewadams/dev/aspect.js-babel7-poc/node_modules/nyc/node_modules/append-transform/index.js:58:13)
    at Module._compile (/Users/matthewadams/dev/aspect.js-babel7-poc/node_modules/pirates/lib/index.js:83:24)
    at Module._extensions..js (internal/modules/cjs/loader.js:699:10)
    at /Users/matthewadams/dev/aspect.js-babel7-poc/node_modules/nyc/node_modules/append-transform/index.js:62:4
    at newLoader (/Users/matthewadams/dev/aspect.js-babel7-poc/node_modules/pirates/lib/index.js:88:7)
    at Object.<anonymous> (/Users/matthewadams/dev/aspect.js-babel7-poc/node_modules/nyc/node_modules/append-transform/index.js:62:4)
    at Module.load (internal/modules/cjs/loader.js:598:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
    at Function.Module._load (internal/modules/cjs/loader.js:529:3)
    at Module.require (internal/modules/cjs/loader.js:636:17)
    at require (internal/modules/cjs/helpers.js:20:18)
    at Object.<anonymous> (/Users/matthewadams/dev/aspect.js-babel7-poc/lib/test/integration/Thing.spec.js:9:15)
    at Module._compile (internal/modules/cjs/loader.js:688:30)
    at Module.replacementCompile (/Users/matthewadams/dev/aspect.js-babel7-poc/node_modules/nyc/node_modules/append-transform/index.js:58:13)
    at Module._compile (/Users/matthewadams/dev/aspect.js-babel7-poc/node_modules/pirates/lib/index.js:83:24)
    at Module._extensions..js (internal/modules/cjs/loader.js:699:10)
    at /Users/matthewadams/dev/aspect.js-babel7-poc/node_modules/nyc/node_modules/append-transform/index.js:62:4
    at newLoader (/Users/matthewadams/dev/aspect.js-babel7-poc/node_modules/pirates/lib/index.js:88:7)
    at Object.<anonymous> (/Users/matthewadams/dev/aspect.js-babel7-poc/node_modules/nyc/node_modules/append-transform/index.js:62:4)
    at Module.load (internal/modules/cjs/loader.js:598:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
    at Function.Module._load (internal/modules/cjs/loader.js:529:3)
    at Module.require (internal/modules/cjs/loader.js:636:17)
    at require (internal/modules/cjs/helpers.js:20:18)
    at /Users/matthewadams/dev/aspect.js-babel7-poc/node_modules/mocha/lib/mocha.js:250:27
    at Array.forEach (<anonymous>)
    at Mocha.loadFiles (/Users/matthewadams/dev/aspect.js-babel7-poc/node_modules/mocha/lib/mocha.js:247:14)
    at Mocha.run (/Users/matthewadams/dev/aspect.js-babel7-poc/node_modules/mocha/lib/mocha.js:576:10)
    at Object.<anonymous> (/Users/matthewadams/dev/aspect.js-babel7-poc/node_modules/mocha/bin/_mocha:637:18)
    at Module._compile (internal/modules/cjs/loader.js:688:30)
    at Module.replacementCompile (/Users/matthewadams/dev/aspect.js-babel7-poc/node_modules/nyc/node_modules/append-transform/index.js:58:13)
    at Module._extensions..js (internal/modules/cjs/loader.js:699:10)
    at Object.<anonymous> (/Users/matthewadams/dev/aspect.js-babel7-poc/node_modules/nyc/node_modules/append-transform/index.js:62:4)
    at Module.load (internal/modules/cjs/loader.js:598:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
    at Function.Module._load (internal/modules/cjs/loader.js:529:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:741:12)
    at runMain (/Users/matthewadams/.node-spawn-wrap-38692-42f74de48f81/node:68:10)
    at Function.<anonymous> (/Users/matthewadams/.node-spawn-wrap-38692-42f74de48f81/node:171:5)
    at Object.<anonymous> (/Users/matthewadams/dev/aspect.js-babel7-poc/node_modules/nyc/bin/wrap.js:23:4)
    at Module._compile (internal/modules/cjs/loader.js:688:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10)
    at Module.load (internal/modules/cjs/loader.js:598:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
    at Function.Module._load (internal/modules/cjs/loader.js:529:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:741:12)
    at /Users/matthewadams/.node-spawn-wrap-38692-42f74de48f81/node:178:8
    at Object.<anonymous> (/Users/matthewadams/.node-spawn-wrap-38692-42f74de48f81/node:181:3)
    at Module._compile (internal/modules/cjs/loader.js:688:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10)
    at Module.load (internal/modules/cjs/loader.js:598:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
    at Function.Module._load (internal/modules/cjs/loader.js:529:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:741:12)
    at startup (internal/bootstrap/node.js:285:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:739:3)
@matthewadams matthewadams changed the title "Cannot read property 'value' of undefined" when using from Node.js 10.12.0, plain JavaScript project that uses Babel 7 Getting "Cannot read property 'value' of undefined" when using from Node.js 10.12.0, plain JavaScript project that uses Babel 7 Nov 11, 2018
@matthewadams matthewadams changed the title Getting "Cannot read property 'value' of undefined" when using from Node.js 10.12.0, plain JavaScript project that uses Babel 7 Getting "Cannot read property 'value' of undefined" when using aspect.js from Node.js 10.12.0, plain JavaScript project that uses Babel 7 Nov 11, 2018
@mgechev
Copy link
Owner

mgechev commented Nov 11, 2018

I'm not familiar with the difference of the implementations of the decorators spec between Babel and TypeScript.

If anyone is using aspect.js with Babel, it would be great if you can share your experience.

@matthewadams
Copy link
Collaborator Author

@mgechev Thanks to https://babeljs.slack.com/archives/C0DFJT81H/p1542152010508400, I was able to workaround this issue. Relevant commit is matthewadams/aspect.js-babel7-poc@ba2e9d3.

The key fix was to set legacy to true; see matthewadams/aspect.js-babel7-poc@ba2e9d3#diff-b9cfc7f2cdf78a7f4b91a753d10865a2L67.

Running npm t fixed the tests, but I also had to change one other thing: the this reference in MethodCallCounterAspect looks like it's not getting set correctly, so I can't use state in my aspects. I'll open a separate issue for that.

I'll close this issue and open another one to support the modern behavior of @babel/plugin-proposal-decorators.

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

No branches or pull requests

2 participants