Использование grunt-html-build
Я получаю ошибку Warning: undefined is not a function Use --force to continue.
при попытке запустить html-grunt-build. Ниже приведена дополнительная информация, любая помощь будет принята с благодарностью:
$ grunt htmlbuild --verbose
Initializing
Command-line options: --verbose
Reading "Gruntfile.js" Gruntfile...OK
Registering Gruntfile tasks.
Initializing config...OK
Loading "Gruntfile.js" tasks...OK
+ build, default
Running tasks: htmlbuild
Loading "grunt-html-build" plugin
Registering "/home/path/node_modules/grunt-html-build/tasks" tasks.
Loading "build-html.js" tasks...OK
+ htmlbuild
Running "htmlbuild" task
Running "htmlbuild:dist" (htmlbuild) task
Verifying property htmlbuild.dist exists in config...OK
Files: path/to/css/css.html -> path/to/css/css.html
Options: beautify=false, logOptionals=false, relative, scripts={}, styles={"critical":"path/to/css/critical.css"}, sections={}, data={}, parseTag="build"
Reading path/to/css/css.html...OK
Reading path/to/css/critical.css...OK
Warning: undefined is not a function Use --force to continue.
Aborted due to warnings.
Мой конфиг Grunt (я использую load-grunt-config, поэтому он хранится в отдельном файле):
module.exports = function(grunt, options) {
return {
dist: {
src: 'path/to/css/css.html',
dest: 'path/to/css/css.html',
options: {
styles: {
critical: 'path/to/css/critical.css'
}
}
}
};
};
Более подробная ошибка:
TypeError: undefined is not a function
at Object.validators.validate (/home/node_modules/grunt-html-build/tasks/build-html.js:196:44)
at /home/node_modules/grunt-html-build/tasks/build-html.js:245:39
at Array.forEach (native)
at transformContent (/home/node_modules/grunt-html-build/tasks/build-html.js:242:14)
at /home/node_modules/grunt-html-build/tasks/build-html.js:306:27
at Array.forEach (native)
at /home/node_modules/grunt-html-build/tasks/build-html.js:295:22
at Array.forEach (native)
at Object.<anonymous> (/home/node_modules/grunt-html-build/tasks/build-html.js:291:20)
at Object.<anonymous> (/home/node_modules/grunt/lib/grunt/task.js:264:15)
2 ответа
Поэтому проблема заключалась в том, что я использовал grunt-usemin и grunt-html-build в одном и том же HTML-файле.
grunt-html-build видел мои теги сборки:
<!-- build:css path/to/css/ie8.min.css -->
<link rel="stylesheet" href="path/to/css/ie8.css">
<link rel="stylesheet" href="path/to/css/print-new.css" media="print">
<!-- endbuild -->
И он не знал, как бороться с build:css
Чтобы решить эту проблему, я разделил два файла на разные HTML-включения, чтобы задачи могли выполняться отдельно.
У меня возникла та же проблема после обновления lodash с 3.x до 4.x
Понижение версии lodash до 3.x исправляет это для меня, поэтому кажется, что это проблема совместимости с grunt-usemin и lodash 4.x