Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

184
Visualizações
How to hide node_modules of a child project in node.js/webpack?

I have two Vue 3 projects - a library and a main project.

Library
I build this project as Vue 3 library

vue-cli-service build --target lib --name index src/index.common.ts

In this project I use js-joda:

"dependencies": {
    "@js-joda/core": "^5.2.0",
    ...
}

in order to remove node_modules of the library from webpack bundle I do the following in the library vue.config.js:

const nodeExternals = require('webpack-node-externals');
...
configureWebpack: config => {
  config.target = 'node';
  config.externalsPresets = { node: true }; 
  config.externals = [nodeExternals()]; 
},

Main project
I also use js-joda in this project and as my library is local I have the following in package.json:

"dependencies": {
    "@js-joda/core": "^5.2.0",
    "my-lib": "file:./../../my-lib",
     ...
}

Problem
When I build main project, with the configuration I described above, two versions of js-joda library are included in JS bundles . One version is taken from main-project/node_modules and another from my-lib/nodes_modules. As a result I have different function instances with the same name what gives me wrong results in my code.

If I remove my-lib/nodes_modules before building main project then everything is ok. However, to do it every time before building main project isn't a good solution. Besides I work at two projects simultaneously.

Could anyone say, how I can hide my-lib/nodes_modules from main project in a better way?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

In your library, you should list js-joda under peerDependencies while in your main project you should list js-joda under dependencies.

For more information - https://nodejs.org/es/blog/npm/peer-dependencies/

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda