我只能在全局安装一个npm包

时间:2018-01-19 16:18:31

标签: node.js windows

这是我试图通过常规安装提取包:

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

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

1 个答案:

答案 0 :(得分:1)

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

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

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

  

全球 - 这会将模块放在{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?

修改