When running npm install on a project, and running grunt / gulp to build, you’ll sometimes get errors–especially on older projects. These are some of the hardest to troubleshoot because they’re so dense. So this page will attempt to list out common errors and their fixes.
For pretty much all of these fixes, it’s recommended to first delete the package-lock.json file and node_modules folder, so that you can run things completely fresh without old stuff getting in the way.
jpegtran, jpegbin, gifsicle
Error
When initially running npm install, it errors out at the end and gives you something like this:
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! jpegtran-bin@0.1.7 postinstall: `node pre-build.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the jpegtran-bin@0.1.7 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! /Users/mcooley/.npm/_logs/2021-04-14T15_02_55_170Z-debug.log
Fix
The fix for this is as follows:
- Delete node_modules folder and package-lock.json file.
- Run the following:
npm install --save request@2.81.0
npm install node-sass request@2.81.0
This installs an older version of node and node-sass, which allows you to build.
Primordials
Error
When initially running npm install, it errors out at the end and gives you soomething like this:
fs.js:35
} = primordials;
^
ReferenceError: primordials is not defined
at fs.js:35:5
at req_ (/Users/mcooley/Repos/tompkins_state_bank_46608/development/node_modules/natives/index.js:143:24)
at Object.req [as require] (/Users/mcooley/Repos/tompkins_state_bank_46608/development/node_modules/natives/index.js:55:10)
at Object.<anonymous> (/Users/mcooley/Repos/tompkins_state_bank_46608/development/node_modules/fstream/node_modules/graceful-fs/fs.js:1:37)
at Module._compile (internal/modules/cjs/loader.js:1158:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1178:10)
at Module.load (internal/modules/cjs/loader.js:1002:32)
at Function.Module._load (internal/modules/cjs/loader.js:901:14)
at Module.require (internal/modules/cjs/loader.js:1044:19)
at require (internal/modules/cjs/helpers.js:77:18)
Fix
You need to change the version of node you’re running on. The fix for this is as follows:
- Delete node_modules folder and package-lock.json file.
- Run the following:
nvm use 8.17.0
npm install
This will change your node version to 8.17.0, which will fix the primordials issue.
Missing Binding
Error
After fixing the above error, you may get a second error like this:
/Users/mcooley/Repos/47815_wayne_bank/development/node_modules/node-sass/lib/binding.js:15
throw new Error(errors.missingBinary());
^
Error: Missing binding /Users/mcooley/Repos/47815_wayne_bank/development/node_modules/node-sass/vendor/darwin-x64-57/binding.node
Node Sass could not find a binding for your current environment: OS X 64-bit with Node.js 8.x
Found bindings for the following environments:
- OS X 64-bit with Node.js 12.x
This usually happens because your environment has changed since running `npm install`.
Run `npm rebuild node-sass` to download the binding for your current environment.
at module.exports (/Users/mcooley/Repos/47815_wayne_bank/development/node_modules/node-sass/lib/binding.js:15:13)
at Object.<anonymous> (/Users/mcooley/Repos/47815_wayne_bank/development/node_modules/node-sass/lib/index.js:14:35)
at Module._compile (module.js:653:30)
at Object.Module._extensions..js (module.js:664:10)
at Module.load (module.js:566:32)
at tryModuleLoad (module.js:506:12)
at Function.Module._load (module.js:498:3)
at Module.require (module.js:597:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/Users/mcooley/Repos/47815_wayne_bank/development/node_modules/gulp-sass/index.js:166:21)
Fix
Fortunately, it tells you what to do right in the text of the error itself, which is rare for gulp / grunt errors. Run the following:
npm rebuild node-sass
gulp
This will rebuild the SASS piece, which will fix the error.
Catch / Unexpected Token
Error
npm will appear to be installed successfully, but then when you try to run gulp, you get an error like this:
/development/node_modules/globby/index.js:28
} catch {
^
SyntaxError: Unexpected token {
at new Script (vm.js:51:7)
at createScript (vm.js:136:10)
at Object.runInThisContext (vm.js:197:10)
at Module._compile (module.js:613:28)
at Object.Module._extensions..js (module.js:660:10)
at Module.load (module.js:561:32)
at tryModuleLoad (module.js:501:12)
at Function.Module._load (module.js:493:3)
at Module.require (module.js:593:17)
at require (internal/module.js:11:18)
Fix
You need to change the version of node you’re running on. The fix for this is as follows:
- Delete node_modules folder and package-lock.json file.
- Run the following:
nvm use 10.16.0
npm install
This will change your node version to 10.16.0, which will fix the catch issue.
Old BS2 sites: grunt-contrib and compress.js
Error
This is an old issue that I’m hoping we have already updated on all of our remaining old BS2 sites, but just in case: When trying to grunt a BS2 project, you may see these errors:
Loading "compress.js" tasks...ERROR
>> SyntaxError: Unexpected token *
Warning: Task "compress" not found. Use --force to continue.
Aborted due to warnings.
FAIL
(which just means grunt-contrib-compress isn’t installed) or this one:
>> Uglifying source "src/scripts/script-concat.js" failed.
Warning: Uglification failed.
Cannot create property 'warnings' on boolean 'true'.
but even if you don’t see these errors specifically, if it’s an old BS2 site, it’s worth double-checking these things have been done to the package.json file.
Fix
There are several items to check on the old BS2 sites.
- First, we had to get the site to run on at least npm 8.9.4
- Next,
grunt-contribis no longer being updated, so we had to install its constituent parts we needed:
npm install -D grunt-contrib-compress grunt-contrib-less grunt-contrib-coffee grunt-contrib-uglify grunt-contrib-cssmin grunt-contrib-copy grunt-contrib-concat
Note: also remove the now unnecessary grunt-contrib from the package.json dependencies because it has been known to cause errors if it is still there. This may require you to uninstall and reinstall the node modules if you’d already installed them with grunt-contrib in the list.
- Update the gruntfile.js tasks to the following:
grunt.loadNpmTasks('grunt-contrib-compress');
grunt.loadNpmTasks('grunt-contrib-less');
grunt.loadNpmTasks('grunt-contrib-coffee');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-cssmin');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-copy');
// required for png/img compression
grunt.loadNpmTasks('grunt-contrib-imagemin');
// required for svg images
grunt.loadNpmTasks('grunt-svgmin');
// required for site scaffold
grunt.loadNpmTasks('grunt-cms-site-scaffold');
// required for cms upload
grunt.loadNpmTasks('grunt-cms-upload');
// required for grunt contrib watch
grunt.loadNpmTasks('grunt-contrib-watch');
- In the gruntfile.js, under the “uglify” task, change
compress: truetocompress: {}if it is not already updated. - In the gruntfile.js DEFAULT task, update with:
grunt.registerTask('default', ['less', 'coffee', 'concat', 'uglify', 'imagemin', 'svgmin', 'copy', 'compress']);
- To head off some errors in the COMPRESS task, make sure the Compress task gzip { files : [] } section reads:
files : [
{expand: true, cwd: 'deploy/css/', src: ['*.css'], dest: 'deploy/css/', ext: '.css.gz'},
{expand: true, cwd: 'deploy/js/', src: ['*.js'], dest: 'deploy/js/', ext: '.js.gz'},
{expand: true, cwd: 'deploy/img/', src: ['*.svg'], dest: 'deploy/img/', ext: '.svg.gz'}
]
Specifically, check the ext: '.***.gz' on the end of those lines are there.
- You might still run into a few Uglification and Less errors. Aaron Irons had most of those fixes, but they were few and far between.
Post-Live Devs Documentation
Here is additional documentation post-live devs use for troubleshooting install errors.