Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why is this build failing when NODE_ENV is set to production?

I was having trouble getting npm install to work when NODE_ENV was set to production, and since I don’t have enough depth in Node to understand what was going wrong, I thought I’d ask why that might be the case.

For context:

  • This project uses node 18.14.2

    MEDevel.com: Open-source for Healthcare and Education

    Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

    Visit Medevel

  • package.json includes a script called prepare that simply runs
    husky install, and that’s executed as part of npm install.

  • When NODE_ENV is set to its default value development, npm install to complete successfully:

    file-upload git:(ACW-5868) ✗ export NODE_ENV=development
    file-upload git:(ACW-5868) ✗ npm install                
    
    > @icpsr/file-upload@0.1.29 prepare
    > husky install
    
    husky - Git hooks installed
    
    added 1397 packages, and audited 1845 packages in 5s
    
    236 packages are looking for funding
      run `npm fund` for details
    
    5 moderate severity vulnerabilities
    
    To address all issues (including breaking changes), run:
      npm audit fix --force
    
    Run `npm audit` for details.
    
    
  • However, when it’s set to production, I get this:

    file-upload git:(ACW-5868) ✗ export NODE_ENV=production
    file-upload git:(346b304) npm install
    
    > @icpsr/file-upload@0.1.29 prepare
    > husky install
    
    sh: husky: command not found
    npm ERR! code 127
    npm ERR! path /Users/bhorvath/tmp/file-upload
    npm ERR! command failed
    npm ERR! command sh -c husky install```
    
    

What is going on here? Why is node unable to find an executable that’s within the root directory structure when the build is run in a production environment? (Not that you’d necessarily want to do so btw; I’m just curious.)

>Solution :

You probably ran npm install husky --save-dev to install that package (as the official documentation suggest: https://typicode.github.io/husky/getting-started.html#manual).

--save-dev installs packages used only for development, that’s why you cannot run it in a production environment.

You can check it by opening your package.json file and check if husky is under devDependencies.

To use husky in a production environment, you can refer to the official doc: https://typicode.github.io/husky/guide.html#disable-husky-in-ci-docker-prod

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading