【发布时间】:2022-01-25 09:14:15
【问题描述】:
我有一个依赖于Package1的包Package2。
套餐 1: 由以下文件组成(本例)
package.json
index.js
/bin/package1 (no extension)
包 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"
},
...
包 1 /bin/package1 脚本:
#!/usr/bin/env node
const package1 = require('../');
// just import the package1 module an it should run without function call
包 2 是依赖于包 1 的包。
包 2 package.json:
...
"name": "package2",
"version": "1.0.0",
"description": "a JavaScript library that depends on package1",
"main": "index.js",
"scripts": {
"serve" : "package1 ."
},
...
但是当我运行 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.
我尝试了很多不同的东西,但我无法让它发挥作用。
【问题讨论】:
-
您是否尝试将 .js 扩展名添加到 /bin/package1?
-
是的,我的初始测试是使用 .js 扩展名,在检查了按预期工作的其他包的源代码后,他们没有使用它
标签: javascript node.js