17

It seems that npm install --prefix ./server (with no args) is not working with --prefix flag. I just want to install all packages from package.json. All I get after that command is:

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

All is fine when I put npm install package_name -S --prefix ./server for example. Then NPM will create node_modules in server and will add package_name package.

My files structure is:

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

"Main" package.json contains all scripts (for Heroku and for me) and dependiencies for server. client is Angular2 app that's why it has own node_modules and package.json.

I use NPM 4.2.0. With version 5.0.3 (newest?) it seems that --prefix flag is not working at all.

EDIT #1

I've just discovered that I can solve my problem with npm install (which will install node_modules in my project folder) and then copy node_modules to server/node_modules. Without that copy jasmine throws errors during tsc build.

Now I have to have node_modules in main catalog and copy of them in server. That's so odd..

EDIT #2

According to @Damian Lattenero answer:

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

or

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

IS NOT WORKING and generates:

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

THIS WORKS:

npm --prefix ProjectName/server install ./ProjectName

but generates:

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'

and

package-lock.json next to node_modules

and

empty etc catalog next to node_modules

and

There are some problems with build (tsc -p server) with mongodb package.

tBlabs
  • 2,619
  • 3
  • 18
  • 22

6 Answers6

8

Try:

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

or

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

Also, to understand better what the --prefix do, you can check this two answers:

How to npm install to a specified directory?

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

developer_hatch
  • 15,898
  • 3
  • 42
  • 75
  • First option seems to work but dependently of params I get mass of strange errors. I will list them soon. – tBlabs Jun 09 '17 at 23:07
  • @tBlabs mmm I see, I think that is for a new question, the original one I think is solved, don't you? – developer_hatch Jun 09 '17 at 23:09
  • @tBlabs maybe is confusing if you add all in the same question, the original one is one step forward, maybe the other problems you should ask in a new one, I will glad check it with you – developer_hatch Jun 09 '17 at 23:12
  • I will post new question then. Thank You for help. I'm still checking every combination of Your answer cause very strange things happening here.. – tBlabs Jun 09 '17 at 23:16
3

Works for me

npm install --prefix ./server ./server
Israel
  • 1,165
  • 11
  • 11
1

Running the newest version of Ubuntu (Ubuntu 16.04.2 LTS), I encountered the same problem with npm install. I also got an ENOENT error, indicating that npm cannot find the necessary files.

When I installed nodejs-legacy, as shown here under:

sudo apt-get install nodejs-legacy

npm subsequently compiled fine, and my Angular application deployed as it should.

Flying Dutchman
  • 135
  • 1
  • 6
  • The following packages have unmet dependencies: nodejs-legacy : Depends: nodejs (>= 0.6.19~dfsg1-3~) but it is not going to be installed E: Unable to correct problems, you have held broken packages. Do I need `node` or `nodejs` package? – tBlabs Jun 10 '17 at 09:44
  • The versions I run with under Ubuntu 16.04.2 LTS, are as follows: npm: 5.0.3. node: 4.2.6 The nodejs package contains the nodejs binary as well as npm, so it is unnecessary to install npm separately. However, for some npm packages to run (such as those that require compiling code from source), you will need to install the build-essential package: sudo apt-get install build-essential Regarding nodejs-legacy: This package contains a symlink for legacy Node.js code requiring binary to be /usr/bin/node (not /usr/bin/nodejs as provided in Debian). – Flying Dutchman Jun 10 '17 at 13:26
0

SOLUTION

Those lines in package.json solves all my problems:

"scripts": {

"init": "npm i && mv ./node_modules ./server && sudo npm i typescript -g",

Strange but works...

tBlabs
  • 2,619
  • 3
  • 18
  • 22
0

This part of my server package.json and all working fine:

 "scripts": {
    "start": "node dist/app.js",
    "server": "nodemon --exec ts-node src/app.ts",
    "build": "tsc -p .",
    "client": "npm start --prefix ../client",
    "client:install": "npm install --prefix ../client",
    "client:build": "npm run build --prefix ../client",
    "dev": "concurrently \"npm run server\" \"npm run client\""
  },
Denis
  • 300
  • 2
  • 10
0

Try this one it will definitely work, I'm assuming your project root directory package.json also has dependencies.

npm install && npm install --prefix ./server && npm install --prefix ./client

or user this script

"scripts": {
    "client-install": "npm install --prefix ./client",
    "install-all": "npm install && npm run client-install && npm run server-install",
    "server-install": "npm install --prefix ./server",
  },
CoderOO7
  • 121
  • 2
  • 5