-
-
Notifications
You must be signed in to change notification settings - Fork 25
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
TypeError: Cannot access private method #60
Comments
Hi, What version of node are you using? it looks like i didn't bump the 'engines' value in package.json when releasing 10.0.0 which marks that method as private. |
Hi, finally I had some time to show the errors, I am tiny -lru in vuex, node version 18.13.0
with tiny -lru version 9.0.3, it working fine. However, when I upgrade to version 10+, I encounter error like this Hope this help ! |
If you have a Proxy calling the cache, is the context of the call changing? what is "this" via breakpoint at that line (81)? it should be I'm assuming you're using an invalid browser or node, but you're not providing enough info to help. If 9.x works, the context should be correct and you're using a version your rte can't run, or you're calling it incorrectly. |
can you share the code that creates the proxy; the issue is the usage of the proxy. |
The proxy getter needs to rewritten; however you shouldn't use a proxy on things with private fields. They're also really slow. class Example {
#world = "world";
hello(){
console.log(`Hello ${this.#world}`);
}
}
const exampleProxy = new Proxy(new Example(), {
has: function (obj, prop) {
return prop in obj;
},
get(target, prop, receiver) {
return (params) => {
return target[prop](params);
}
},
set: function (obj, prop, value) {
obj[prop] = value;
return this;
}
}); |
In the future please provide a sample like this; chance of me trying to recreate your issue is very small. |
I use in vuex , a bit complicated to show code because it also had html ( My code is running in browser ). The code roughly like this import { createStore } from 'vuex'
import { lru } from "tiny-lru"
const store = createStore({
state: {
cache: lru(200)
},
getters: {
get: (state) => (key) => {
return state.cache.get(key);
},
},
mutations: {
set(state, payload) {
state.cache.set(payload.key, payload.value);
}
}
})
// usage, not sure if could call like `store.getters.get(key);`
var cache = this.$store.getters.get(key); This had no issue on tiny-lru version 9.0.3 but not version above 9.0.3, the error show as comment above ( cannot access private method ) |
I know, because at 10.0.0 it became a private method and your proxy code doesn't handle that. So your options are to use 9.x.x or update your code to handle privates. |
I see, thanks ! |
Might be worth opening an issue with vuex if you can't override/patch the proxy. |
I will stick to version 9 since I not have clear idea of how proxy and private method work. |
I'm curious about the scope of this issue, proxies affecting interoperability wasn't a consideration when I set the field to private. |
@kiwionly try 11.0.0; the private field was replaced with the same function in scope so that should work with the proxy. |
@avoidwork I just upgrade to version 11 and it work as expected, thanks ! |
Hello,
I am using version 10.0.1 and encounter this issue when call get(), below show error in my browser console:
which turn out to be here:
however, that is no issue at version 9.0.3
The text was updated successfully, but these errors were encountered: