9
votes

I'm starting a simple HTML project with Bootstrap 4 where I want to use compiled sass. To do this I've installed grunt using node.js and later steps described on https://gruntjs.com/getting-started.

When I'm typing grunt command the result is:

Error: Cannot find module 'liftoff' at Function.Module._resolveFilename (internal/modules/cjs/loader.js:603:15) at Function.Module._load (internal/modules/cjs/loader.js:529:25) at Module.require (internal/modules/cjs/loader.js:658:17) at require (internal/modules/cjs/helpers.js:22:18) at Object. (C:\Bitnami\nodejs-7.3.0-0\nodejs\node_modules\grunt-cli\bin\grunt:7:15) at Module._compile (internal/modules/cjs/loader.js:722:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:733:10) at Module.load (internal/modules/cjs/loader.js:620:32) at tryModuleLoad (internal/modules/cjs/loader.js:560:12) at Function.Module._load (internal/modules/cjs/loader.js:552:3)

I've tried to figure out this by installing npm install liftoff. This module was installed properly but still I cannot run grunt.

My gruntfile.js looks like this:

module.exports = function(grunt) {
'use strict';

grunt.initConfig({
    watch: {
        sass: {
            files: ['sass/**', 'Gruntfile.js'],
            tasks: ['sass'],
        },
        uglify: {
            files: ['js/index.js', 'Gruntfile.js'],
            tasks: ['uglify'],
        }
    },
    sass: {
        production: {
            options: {
                compress: true,
                strictUnits: true
            },
            files: {
                'styles.css': 'styles/styles.sass',
            }
        }
    },
    uglify: {
        options: {
            beautify: true,
            mangle: false,
            compress: {
                drop_console: true
            }
        },
        build: {
            files: {
                'index.min.js': ['js/index.js'],
            }
        }
    }
});

grunt.registerTask('default', ['css', 'js']);
grunt.registerTask('css', ['sass']);
grunt.registerTask('js', ['uglify']);

grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-sass');
grunt.loadNpmTasks('grunt-contrib-uglify');
};

What am I missing? I'm quite new to npm grunt so maybe solution is simple but I didn't find answer strictly related to 'liftoff' module. I'm trying to do this on Windows 7. Thanks for any help.

2
Since I didn't get the answer I've found out that any project on this computer has problem with grunt. And the error is the same. So it must be a global problem, not only with this project. I've reinstalled node.js and grunt but it didn't work. :( I've installed gulp and everything is ok.nymphais

2 Answers

6
votes

I've faced the same issue under Ubuntu 20.04 and I believe it's caused by several versions of nodejs.

I have installed nodejs 12.16.2 manually (extracted to /usr/local) and that was my mistake. Once I tried to install grunt from Ubuntu package manager it installed nodejs 10.X as a dependency of node-grunt-cli package.

As a result I had the same error message.

The solution was to remove manually installed nodejs and re-install it from package manager.

2
votes

I also hit this on a clean install on Ubuntu 20.04. I eventually hunted down a recipe at https://ask.openrouteservice.org/t/cannot-find-module-liftoff/1718/5 that seems to fix the problem (not sure why) using nvm to install node v14.16.1, then install grunt-cli globally and grunt locally:

nvm install v14.16.1
npm install -g grunt-cli
npm install grunt