简体   繁体   English

有没有办法让 npm install 在本地 node_modules 目录(the.bin 目录)中安装“bin”可执行文件?

[英]Is there a way to get npm install to install "bin" executables in the local node_modules directory (the .bin directory)?

I have a Node project, and I can npm pack it into a tarball and install it in another directory for testing.我有一个 Node 项目,我可以npm pack成一个 tarball,然后安装到另一个目录中进行测试。 When I do that, the set of files in the "bin" clause of my package.json are correctly symlinked into the node_modules/.bin directory there.当我这样做时,我的package.json的“bin”子句中的文件集被正确地符号链接到那里的node_modules/.bin目录中。 Thus I can use npx something to run the "something" script and it works as I would expect.因此,我可以使用npx something来运行“something”脚本,并且它按我预期的那样工作。

From the actual project directory, however, npm install doesn't do that.然而,在实际的项目目录中, npm install不会这样做。 The scripts are there in my top-level "bin" directory of course, but npx doesn't find them.这些脚本当然在我的顶级“bin”目录中,但npx找不到它们。 Obviously I could just run them directly, but it would be nice if I could run the same shell commands to run them in other installation directories and in the project home directory.显然我可以直接运行它们,但如果我可以运行相同的 shell 命令以在其他安装目录和项目主目录中运行它们,那就太好了。

I don't want to install the package globally;不想全局安装 package; I want to keep everything local, at least for now.我想把所有东西都放在本地,至少现在是这样。 So can I get npm to make those symlinks for me, or should I just bite the bullet and do it myself?那么我可以获取npm来为我创建这些符号链接,还是我应该硬着头皮自己做?

Here's my package.json :这是我的package.json

{
  "name": "@foo/plazadb",
  "version": "0.1.0",
  "description": "Basic database setup with upload/download from CSV",
  "main": "lib/plazadb.js",
  "author": "Pointy",
  "license": "ISC",
  "dependencies": {
    "arg": "^5.0.1",
    "cls-hooked": "^4.2.2",
    "csv-parser": "^3.0.0",
    "csv-stringify": "^6.0.5",
    "neat-csv": "^7.0.0",
    "pg": "^8.7.*",
    "sequelize": "^6.16.*"
  },
  "bin": {
    "conntest": "./bin/conntest.js",
    "download": "./bin/download.js",
    "upload": "./bin/upload.js"
  }
}

The "bin" files all exist (of course, otherwise they would never work). “bin”文件都存在(当然,否则它们将永远无法工作)。 What I'm trying (out of ignorance) is a simple npm install from the project directory.我正在尝试(出于无知)是从项目目录进行简单的npm install

One way to do is by一种方法是通过

  1. specifying a local prefix by using npm config set prefix <path> or one of these methods linked here .使用npm config set prefix <path>此处链接的其中一种方法指定本地前缀。
  2. generating symlinks using npm link使用npm link

As a word of caution, to undo npm link executing npm unlink.请注意,要撤消npm link ,请执行npm unlink. may not work .可能行不通 Instead one may have to run npm uninstall -g.相反,可能必须运行npm uninstall -g. . .

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 npm安装在不在node_modules /中的模块上 - npm install on modules not in node_modules/ Npm i ts-node-dev --save-dev 导致没有这样的文件或目录,chmod node_modules/ts-node-dev/lib\bin.js' - Npm i ts-node-dev --save-dev leads to no such file or directory, chmod node_modules/ts-node-dev/lib\bin.js' sh: /Users/mac/Desktop/LOGIC/node_modules/.bin/react-scripts: /bin/sh^M: 错误的解释器:没有这样的文件或目录 - sh: /Users/mac/Desktop/LOGIC/node_modules/.bin/react-scripts: /bin/sh^M: bad interpreter: No such file or directory npm install 没有创建 node_modules 文件夹 - npm install not creating node_modules folder node.js / npm-覆盖本地默认模块目录(node_modules) - node.js / npm - override local default modules directory (node_modules) 安装目录“/usr/local/bin”不可写 - 如何解决这个问题? 我正在尝试全局安装作曲家 - The installation directory "/usr/local/bin" is not writable - How to fix this? I am trying to install the composer globally npm 安装不会创建 node_modules 文件夹 - npm install doesnt create the node_modules folder 为什么 npm 安装不安装包到 /node_modules 文件夹? - Why is npm install not installing packages into /node_modules folder? 当“ node_modules”退出时,“ npm install”是什么? - What does “npm install” when “node_modules” exits? 是否安装没有符号链接的npm本地模块目录? - Install npm local module directory without symlinks?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM