Closed J-Rojas closed 5 years ago
@lbogdan suggested on the forums that I look into Yarn 'peer dependencies' as a workaround for this problem.
I have built couple of plugins with Vue CLI, did pretty much what you describe and didn't have a problem so it might be necessary to provide a runnable reproduction (as is required anyway by the issue rules).
But generally, the lib should have Vue as a peerDependency, not a normal dependency
Hello! This issue has gone quiet. Spooky quiet. 👻
We get a lot of issues, so we currently close issues requiring feedback after 20 days of inactivity. It’s been at least 10 days since the last update here. If we missed this issue or if you want to keep it open, please reply here. (A maintainer can also add the label not stale
to keep this issue open.)
Thanks for being a part of the Vue community! 💪💚️
Hey again! 😸️
It’s been 20 days since anything happened on this issue, so our friendly neighborhood robot (that’s me!) is going to close it.
Please keep in mind that I’m only a robot, so if I’ve closed this issue in error, I’m HUMAN_EMOTION_SORRY
. 🤖 Please feel free to reopen this issue or create a new one if you need anything else.
Thanks again for being part of the Vue community! 💚️
Ran into this too. Having a dependency that imports vue as a non-peer-dependency itself will cause Vue to be loaded multiple times causing all kind of issues. @LinusBorg thank you for the clarification.
I have ran into this problem too. I add "peerDependents":{"vue": "^2.6.6"} in the library‘s package.json, and it worked. @LinusBorg is right, thank you. At last I noticed that vue-cli is not very suitable for developing a library compared to an app althouth it privide a library build target. It did not privide an api like 'vue create my-library' and init the directory structure for a library.
I think this issue is caused by how Vue CLI aliases Vue in Webpack's config:
resolve: {
alias: {
vue$: 'vue/dist/vue.runtime.esm.js',
},
},
In one case this path is relative to the library node_modules
and in the other case to the project node_modules
.
I therefor overridded it in the vue.config.js
of the project to make it absolute:
const path = require('path');
module.exports = {
configureWebpack: {
resolve: {
alias: {
vue$: path.resolve('./node_modules/vue/dist/vue.runtime.esm.js'),
},
},
},
};
With this change Vue is present only once in my project bundle.
Note that this cannot be fixed by moving Vue to peerDependencies
in the library. I need Vue in development for the library to work properly.
Does anyone know how to solve this problem in case a library was built with --inline-vue and then loaded async using a script tag?
I didn't face issue when using vue2, but the same library and method is now causing all kinds of issues in vue3. I tried removing --inline-vue but this caused method undefined for methods like defineComponent etc., probably because the library cannot find the host's vue instance during runtime.
I think this issue is caused by how Vue CLI aliases Vue in Webpack's config:
resolve: { alias: { vue$: 'vue/dist/vue.runtime.esm.js', }, },
In one case this path is relative to the library
node_modules
and in the other case to the projectnode_modules
.I therefor overridded it in the
vue.config.js
of the project to make it absolute:const path = require('path'); module.exports = { configureWebpack: { resolve: { alias: { vue$: path.resolve('./node_modules/vue/dist/vue.runtime.esm.js'), }, }, }, };
With this change Vue is present only once in my project bundle.
Note that this cannot be fixed by moving Vue to
peerDependencies
in the library. I need Vue in development for the library to work properly.
Saved our heads, buddy. Thanks!
Version
3.9.2
Environment info
Steps to reproduce
You will need two Vue projects, one will need be a library, the other a standard Vue project.
1) Build the Vue library project (--target lib) 2) Run
npm link
within the library project folder. 3) Runnpm link
within the standard project folder. 4) In the standard project, ensure that symlink resolution is disabled in webpack5) Build a Vue project using the library project as a dependency with
npm run serve
(Using Webpack HMR dev-server) 6) Load webpage dev console, you will notice multiple messages: 'You are running Vue in development mode. Make sure to turn on production mode when deploying for production. See more tips at https://vuejs.org/guide/deployment.html'This indicates more than one Vue instance is running.
What is expected?
Only one Vue instance should be running.
What is actually happening?
Multiple Vue instances are loaded (one runtime within the library, one runtime within the standard project).
This issue affects global variable assignment on the Vue instance. If the library expects global variables to be installed on the Vue instance, they will not be shared between the library and the standard project due to the Vue module runtime being loaded twice and essentially being two different objects.
I worked around the issue by deleting the 'vue.runtime.esm.js' file in the library project's node_modules directory. This isn't ideal of course. It seems like the vue-cli that runs Webpack should exclude the second runtime somehow. I was not able to figure out how to do this with the webpack configuration within Vue.config.js.
Another developer ran into this problem without there being a satisfactory solution: https://github.com/vuejs/vuex/issues/842 https://stackoverflow.com/questions/52048395/using-vuex-store-with-npm-link-in-vue-cli-3-project-loses-store