Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

192
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!