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

199
Visualizações
Call JS package as npm script into another package

I have a package Package2 that depends on Package1.

Package 1: consists of the following files (for this example)

      package.json
      index.js
      /bin/package1 (no extension)

Package 1 package.json:

      ...
      {
      "name": "package1",
      "version": "0.0.1",
      "description": "a JavaScript library that should be called by other stuff",
      "main": "index.js",
      "scripts": {
        "bin": "cli.js"
      },
      ...

Package 1 /bin/package1 script:


      #!/usr/bin/env node
      const package1 = require('../'); 
      // just import the package1 module an it should run  without function call

Package 2 is a package that depends on package1.

Package 2 package.json:

      ...
      "name": "package2",
      "version": "1.0.0",
      "description": "a JavaScript library that depends on package1",
      "main": "index.js",
      "scripts": {
        "serve" : "package1 ."
      },
      ...

But I'm getting an error when I run yarn serve:

yarn run v1.22.17
$ package1 .
'package1' is not recognized as an internal or external command,
operable program or batch file.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

I've tried a lol of different things, but I can't get it to work.

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

0

You will need to add this after the "scripts" tag into package 1's package.json:


    ...
    "scripts": {....},
    "bin": {
        "package1": "bin/package1"
      },
    ...

and that's it

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