gpt4 book ai didi

node.js - npm 安装不适用于 --prefix

转载 作者:搜寻专家 更新时间:2023-10-31 23:15:56 25 4
gpt4 key购买 nike

npm install --prefix ./server(没有参数)似乎无法使用 --prefix 标志。我只想安装 package.json 中的所有包。我在该命令之后得到的是:

npm WARN enoent ENOENT: no such file or directory, open '/home/.../ProjectName/server/package.json'

例如,当我放置 npm install package_name -S --prefix ./server 时,一切都很好。然后 NPM 将在 server 中创建 node_modules 并添加 package_name 包。

我的文件结构是:

ProjectName
|
+-- client
| +-- node_modules
| +-- package.json
+-- server
| +-- node_modules
+-- package.json

"Main"package.json 包含所有脚本(对于 Heroku 和我而言)和服务器的依赖项。client 是 Angular2 应用程序,这就是它拥有自己的 node_modules 和 package.json 的原因。

我使用 NPM 4.2.0。对于 5.0.3 版(最新?),--prefix 标志似乎根本不起作用。

编辑 #1

我刚刚发现我可以使用 npm install 解决我的问题(它将在我的项目文件夹中安装 node_modules)然后复制 node_modulesserver/node_modules。如果没有该副本,jasmine 会在 tsc 构建期间抛出错误。

现在我必须在主目录中有 node_modules 并将它们复制到 server 中。这太奇怪了..

编辑 #2

根据 @Damian Lattenero 的回答:

npm --prefix ./server install ./ProjectName/package.json

npm --prefix ProjectName/server install ./ProjectName/package.json

不工作并生成:

npm ERR! code ENOLOCAL npm ERR! Could not install "RecursiveNotebook3/package.json" as it is not a directory and is not a file with a name ending in .tgz, .tar.gz or .tar

这有效:

npm --prefix ProjectName/server install ./ProjectName

但生成:

npm WARN saveError ENOENT: no such file or directory, open '/home/tb/Projects/RecursiveNotebook3/server/package.json' npm notice created a lockfile as package-lock.json. You should commit this file. npm WARN enoent ENOENT: no such file or directory, open '/home/ tb/Projects/RecursiveNotebook3/server/package.json'

node_modules 旁边的

package-lock.json

node_modules 旁边的

etc 目录

用 mongodb 包构建 (tsc -p server) 有一些问题。

最佳答案

尝试:

npm --prefix ./server install ./ProjectName/package.json

npm install --prefix ./server ./ProjectName/package.json

此外,为了更好地理解 --prefix 的作用,您可以查看这两个答案:

How to npm install to a specified directory?

npm - install dependencies for a package in a different folder?

关于node.js - npm 安装不适用于 --prefix,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44467600/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com