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.
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