【发布时间】:2019-04-23 19:58:42
【问题描述】:
我正在使用 Bootstrap 4 开始一个简单的 HTML 项目,我想在其中使用已编译的 sass。为此,我使用 node.js 安装了 grunt,并在 https://gruntjs.com/getting-started 中描述了后续步骤。
当我输入grunt 命令时,结果是:
错误:在以下位置找不到模块“liftoff” Function.Module._resolveFilename (内部/模块/cjs/loader.js:603:15) 在 Function.Module._load (internal/modules/cjs/loader.js:529:25) 在 Module.require (internal/modules/cjs/loader.js:658:17) 在需要(内部/模块/cjs/helpers.js:22:18) 在对象。 (C:\Bitnami\nodejs-7.3.0-0\nodejs\node_modules\grunt-cli\bin\grunt:7:15) 在 Module._compile (internal/modules/cjs/loader.js:722:30) 在 Object.Module._extensions..js (internal/modules/cjs/loader.js:733:10) 在 Module.load (internal/modules/cjs/loader.js:620:32) 在 tryModuleLoad (internal/modules/cjs/loader.js:560:12) 在 Function.Module._load (internal/modules/cjs/loader.js:552:3)
我试图通过安装npm install liftoff 来解决这个问题。此模块已正确安装,但我仍然无法运行grunt。
我的 gruntfile.js 看起来像这样:
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');
};
我错过了什么?我对 npm grunt 很陌生,所以也许解决方案很简单,但我没有找到与“liftoff”模块严格相关的答案。我正在尝试在 Windows 7 上执行此操作。感谢您的帮助。
【问题讨论】:
-
由于我没有得到答案,我发现这台计算机上的任何项目都存在 grunt 问题。错误是一样的。所以它一定是一个全球性的问题,不仅仅是这个项目。我已经重新安装了 node.js 和 grunt 但它没有用。 :( 我已经安装了 gulp,一切正常。