-
Notifications
You must be signed in to change notification settings - Fork 344
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
Cannot import Vue Plugin using Composition API in my project #372
Comments
You don't need to do it in the plugin, using it in the plugin might cause some difficult to spot issues.
The issue is here. When you are using composition API you need to guarantee you are using the same plugin instance! |
Instance? Or do you mean version? I'm pretty confused right now. I have the same version of Composition API across the board and there should only be one instance set in Vue, it's being set in my project. Right now I'm only running Vue.use(VueCompositionApi) inside the project and that results in this error: I even tried to delete How do I go about fixing this? I need to be able to do local development so I can quickly test changes I make in my plugin. |
Hi @Warz , can you share a minimal reproduce repo (best in codesandbox) so we can better help your problem? Thanks. |
I hope this is simple enough: See instructions in README.md. I wasn't sure how I'd do this in codesandbox. After setup you can find this file and remove line 4 and 8 |
seems to be working to me, I'm using EDIT: Not working with npm EDIT2: has I said is because there's two instance of composition-api running, you can easily test by:
If only 1 instance is running it should output either one of those logs, but is logging both: This has to do on how the npm resolves the dependencies, plugin node_modules has priority over project node_modules when trying to resolve the dependency in the project |
Yes, you are correct. I have not tried yarn, but i'd really like to make this work with npm as well. The only place importing composition api is in the functions, for example here is useMultiTree.js from the plugin
If I comment out the import line from useMultiTree.js and useTreeActions.js I'm not getting the console.log output for the plugin composition api node_modules, but obviously that breaks the functions. Any idea how I would go about fixing this? I tried setting resolve alias in the project webpack to force it to use the one in my project:
but didn't make any difference. Maybe there's some documentation detailing this specific issue? |
That's a module resolver issue , either I'm surprised If you find a solution please share here. |
@Warz FWIW your alias resolve fixed it for me. my vue.config is is in the same dir as my node_modules btw - '@vue/composition-api': path.resolve(path.join(__dirname, '../node_modules/@vue/composition-api/'))
+ '@vue/composition-api': path.resolve(path.join(__dirname, './node_modules/@vue/composition-api/')) |
I'm using webpack, changing to that just results in error Can you post full code? |
BTW, have a look at vue-demi :) |
Can you update your code to the repo and share again? Thanks |
I've now comitted the latest changes Running |
@Warz you are packing @vue/composition-api into your plugin - which you shouldn't. Closing for now. Thanks |
What do you mean? I've set it as a peer dependency? |
Like this ? *
Doing that put me back at this point:
|
in your module.exports = {
chainWebpack: config => {
config.merge({
externals: ['vue', '@vue/composition-api'],
})
},
} |
add '@vue/composition-api' to webpack externals solve my problem; |
A project and a plugin. The plugin contains Composition API functions that I want to consume in my project. My project is using Composition API already.
But, I can't figure out a way to import plugin in my project successfully. What I present below is the closest I've gotten. The script seems to work (?), but it's throwing warnings such as this;
[Vue warn]: The setup binding property "multiTree" is already declared.
index.js (in project)
index.js (in plugin)
If I remove
Vue.use(VueCompositionApi);
from plugin, I will get this error in my project:Error in data(): "Error: [vue-composition-api] must call Vue.use(plugin) before using any function."
This doesn't make sense to me. I already called Vue.use(VueCompositionApi) in my project. The line shouldn't be required inside of plugin. Right?
Please note that the plugin is located in another folder, and I'm including it like this:
"vue-jstree-extended": "file:../jstree-extended-warz/vue-jstree"
(I've also attempted using
npm link
, makes no difference)I've read similar issues: #228 #340 #356 #181 which led me to discover peerDependencies, I've set up Composition API as a peerDependency in plugin.
I've also attempted to import both Vue and Composition API in the plugin, this results in the following error in project while performing actions in the tree:
vue.esm.js:629 [Vue warn]: You may have an infinite update loop in a component render function.
So the question is really, how can I get rid of Vue.use(VueCompositionApi) from my plugin?
Any ideas?
The text was updated successfully, but these errors were encountered: