【问题标题】:I can ONLY install an npm package globally我只能在全球范围内安装一个 npm 包
【发布时间】:2018-01-19 16:18:30
【问题描述】:

这是我试图通过常规安装拉取一个包:

PS C:\temp> npm install aws-sam-local

> aws-sam-local@0.2.4 postinstall C:\temp\node_modules\aws-sam-local
> go-npm install

Downloading from URL: https://github.com/awslabs/aws-sam-local/releases/download/v0.2.4/sam_0.2.4_windows_amd64.tar.gz
fs.js:766
  return binding.rename(pathModule._makeLong(oldPath),
                 ^

Error: ENOENT: no such file or directory, rename 'C:\temp\node_modules\aws-sam-local\bin\sam.exe' -> 'C:\temp\node_modul
es\aws-sam-local\node_modules\.bin\sam.exe'
    at Object.fs.renameSync (fs.js:766:18)
    at C:\temp\node_modules\go-npm\bin\index.js:62:12
    at C:\temp\node_modules\go-npm\bin\index.js:51:9
    at ChildProcess.exithandler (child_process.js:267:7)
    at emitTwo (events.js:126:13)
    at ChildProcess.emit (events.js:214:7)
    at maybeClose (internal/child_process.js:925:16)
    at Socket.stream.socket.on (internal/child_process.js:346:11)
    at emitOne (events.js:116:13)
    at Socket.emit (events.js:211:7)
npm WARN enoent ENOENT: no such file or directory, open 'C:\temp\package.json'
npm WARN temp No description
npm WARN temp No repository field.
npm WARN temp No README data
npm WARN temp No license field.

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! aws-sam-local@0.2.4 postinstall: `go-npm install`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the aws-sam-local@0.2.4 postinstall script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\meee\AppData\Roaming\npm-cache\_logs\2018-01-19T16_14_18_418Z-debug.log

与全局:

PS C:\temp> npm install --global aws-sam-local

> aws-sam-local@0.2.4 postinstall C:\Users\meee\AppData\Roaming\npm\node_modules\aws-sam-local
> go-npm install

Downloading from URL: https://github.com/awslabs/aws-sam-local/releases/download/v0.2.4/sam_0.2.4_windows_amd64.tar.gz
+ aws-sam-local@0.2.4
added 72 packages in 48.359s

为什么会损坏?如何将此包拉到所有用户都可以访问的特定文件夹?我想我的一些困惑是“全局”在这里甚至意味着什么,因为它仍然将它安装到我用户的文件夹中。

【问题讨论】:

  • no such file or directory, open 'C:\temp\package.json' 也许是因为这个?
  • 那么为什么要全球工作?我不明白有什么区别

标签: node.js windows


【解决方案1】:

你没有package.jsonno such file or directory, open 'C:\temp\package.json'

要在本地安装包,您需要在工作目录中使用 package.json 来跟踪本地依赖项。您可以使用npm init 创建一个package.json

阅读here 了解全局和本地包:

globally - 这会在 {prefix}/lib/node_modules 中删除模块,并将 {prefix}/bin 中的可执行文件,其中{prefix} 通常是一些东西 喜欢/usr/local。它还会在{prefix}/share/man 中安装手册页,如果 他们提供。

本地 - 这会将您的软件包安装在当前 工作目录。节点模块进入./node_modules,可执行文件进入 在./node_modules/.bin/ 中,根本没有安装手册页。

还有How to Install Global Packages?How to Install Local Packages?

编辑:

【讨论】:

  • 我的全局 package.json 在 Windows 上在哪里?
  • 对,但我认为有一些全局 package.json 这就是全局命令没有失败的原因?那个全局包配置在哪里?如果我进入我的全球位置C:\Users\mee\AppData\Roaming\npm,我会看到每个模块的单独 package.json 文件。全局如何为我创建这些但非全局运行命令不能?全局是否自动运行 npm init 的过程?
  • 嗯。好问题。我搜索了很多,但找不到有关 npm 如何跟踪全局包的更多信息。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-01-03
  • 2020-01-22
  • 2016-02-06
  • 2022-01-20
  • 2015-05-31
  • 2022-08-10
  • 1970-01-01
相关资源
最近更新 更多