1

然后安装到其他电脑上检查。安装包后,它依赖我尝试启动它时出错

pm ERR! Linux 4.10.0-38-generic
npm ERR! argv "/home/pavlo/.nvm/versions/node/v6.11.4/bin/node" "/home/pavlo/.nvm/versions/node/v6.11.4/bin/npm" "start" "storjboard"
npm ERR! node v6.11.4
npm ERR! npm  v3.10.10
npm ERR! path /home/pavlo/Desktop/test/package.json
npm ERR! code ENOENT
npm ERR! errno -2
npm ERR! syscall open

npm ERR! enoent ENOENT: no such file or directory, open '/home/pavlo/Desktop/test/package.json'
npm ERR! enoent ENOENT: no such file or directory, open '/home/pavlo/Desktop/test/package.json'
npm ERR! enoent This is most likely not a problem with npm itself
npm ERR! enoent and is related to npm not being able to find a file.
npm ERR! enoent 

npm ERR! Please include the following file with any support request:
npm ERR!     /home/pavlo/Desktop/test/npm-debug.log

问题是我必须从 git 克隆 package.json,如何使用 package.json 正确发布?

注意:命令在 package.json 脚本中启动

我的 json 发布:

{
  "name": "name",
  "version": "0.0.3",
  "description": "Name",
  "main": "script.js",
  "dependencies": {
    "request": "^2.83.0",
  },
  "devDependencies": {},
  "scripts": {
    "test": "mocha",
    "start": "node node_modules/module/script.js"
  },
  "repository": {
    "type": "git",
    "url": "https://github.com/me/module"
  },
  "keywords": [
    "somewords"
  ],
  "author": "me",
  "license": "MIT",
  "bugs": {
    "url": "https://github.com/me/module/issues"
  },
  "homepage": "https://github.com/me/module#readme"
}

在其他 PC 上安装模块时出错 (WARN)

npm WARN enoent ENOENT: no such file or directory, open '/home/pavlo/Desktop/test/package.json'
npm WARN test No description
npm WARN test No repository field.
npm WARN test No README data
npm WARN test No license field.

但在test/node_modules/module/(here there are everything)自述文件、json 和脚本中

4

1 回答 1

0

如果您希望能够从另一个目录启动您的模块,您可以这样做:

在你的模块package.json

{
  "name": "module",
  "scripts": {
    "start": "node script.js"
  }
}

从测试目录(如this answer建议):

npm start --prefix node_modules/module/

或者,您可以通过在测试目录中创建 package.json 文件并添加脚本来启动模块:

{
  "name": "test",
  "scripts": {
    "start": "node node_modules/module/script.js"
  }
}

通常, npm包放在node_modules目录中,因为这些模块应该用作依赖项,而不是直接使用。

这取决于您的应用程序的用途,但也许您可能对执行安装后脚本或全局安装它感兴趣。

npm doc用于软件包安装。

于 2017-11-06T12:01:18.477 回答