red888
red888

Reputation: 31652

I can ONLY install an npm package globally

This is me trying to pull a package with regular install:

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

> [email protected] 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! [email protected] postinstall: `go-npm install`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] 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

With global:

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

> [email protected] 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
+ [email protected]
added 72 packages in 48.359s

Why is this broken and how can I pull this package to a specific folder that all users can access? I guess some of my confusion is what "global" even means here because its still installing it to MY user's folders.

Upvotes: 1

Views: 936

Answers (1)

pzaenger
pzaenger

Reputation: 11993

You have no package.json: no such file or directory, open 'C:\temp\package.json'

To install packages locally you need a package.json in your working directory to keep track of your local dependencies. You can create a package.json with npm init.

Read here to get an understanding about global and local packages:

globally - This drops modules in {prefix}/lib/node_modules, and puts executable files in {prefix}/bin, where {prefix} is usually something like /usr/local. It also installs man pages in {prefix}/share/man, if they’re supplied.

locally - This installs your package in the current working directory. Node modules go in ./node_modules, executables go in ./node_modules/.bin/, and man pages aren’t installed at all.

And also How to Install Global Packages? and How to Install Local Packages?

Edit:

Upvotes: 2

Related Questions