Search code examples
node.jslinuxnpmyarnpkg

Cannot write the output made by npm install to a file in Linux


I am not able to show the output of the package installation progress bar to the file. The others get printed pretty correctly.

I tried redirecting the stderr to stdout and then writing but none of them helped. This was happening with yarn as well.

This is the output that I am seeing in the file:

> @nestjs/core@8.2.3 postinstall node_modules/@nestjs/core
> opencollective || exit 0

                           Thanks for installing nest
                 Please consider donating to our open collective
                        to help us maintain this package.

                            Number of contributors: 0
                              Number of backers: 823
                            Annual budget: US$1,69,285
                            Current balance: US$10,798

             Become a partner: https://opencollective.com/nest/donate


> @prisma/client@3.15.2 postinstall node_modules/@prisma/client
> node scripts/postinstall.js

Environment variables loaded from .env
Prisma schema loaded from prisma/schema.prisma

✔ Generated Prisma Client (3.15.2 | library) to ./node_modules/@prisma/client in 256ms
You can now start using Prisma Client in your code. Reference: https://pris.ly/d/client

import { PrismaClient } from '@prisma/client'
const prisma = new PrismaClient()

┌─────────────────────────────────────────────────────────┐
│  Update available 3.15.2 -> 4.3.1                       │
│                                                         │
│  This is a major update - please follow the guide at    │
│  https://pris.ly/d/major-version-upgrade                │
│                                                         │
│  Run the following to update                            │
│    npm i --save-dev prisma@latest                       │
│    npm i @prisma/client@latest                          │
└─────────────────────────────────────────────────────────┘
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.3.2 (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.3.2: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})

added 927 packages from 735 contributors and audited 928 packages in 38.069s

85 packages are looking for funding
  run `npm fund` for details

found 2 vulnerabilities (1 moderate, 1 high)
  run `npm audit fix` to fix them, or `npm audit` for details

Solution

  • You can do it with the following command:

    npm i react-leaflet -ddd 2>&1 | tee npm-install.log
    

    or if you want to capture colorized output, which is e.g. helpful to differentiate the output of log levels:

    script -q -c "npm i react-leaflet -ddd" npm-install.log
    cat npm-install.log
    

    Use log level flag according to your requirement:

    -d   == --loglevel info
    -dd  == --loglevel verbose 
    -ddd == --loglevel silly