The Broccoli Plugin: [LESSPlugin] failed with: undefined
- OS: Mac OSX (El Capitan)
- Versions: angular-cli: 1.0.0-beta.5 node: 4.3.1 os: darwin x64
- Repro steps. I have installed less css
- The log given by the failure:
Could not start watchman; falling back to NodeWatcher for file system events.
Visit http://ember-cli.com/user-guide/#watchman for more info.
Build failed.
File: input (1029)
The Broccoli Plugin: [LESSPlugin] failed with:
undefined
The broccoli plugin was instantiated at:
at LESSPlugin.Plugin (/Users/julien/Documents/projects/bignibou/bignibou-site/bignibou-client/node_modules/angular-cli/node_modules/broccoli-caching-writer/node_modules/broccoli-plugin/index.js:10:31)
at LESSPlugin.CachingWriter [as constructor] (/Users/julien/Documents/projects/bignibou/bignibou-site/bignibou-client/node_modules/angular-cli/node_modules/broccoli-caching-writer/index.js:21:10)
at new LESSPlugin (/Users/julien/Documents/projects/bignibou/bignibou-site/bignibou-client/node_modules/angular-cli/lib/broccoli/angular-broccoli-less.js:21:12)
at Object.Plugin.build.compile.exports.makeBroccoliTree (/Users/julien/Documents/projects/bignibou/bignibou-site/bignibou-client/node_modules/angular-cli/lib/broccoli/angular-broccoli-less.js:52:12)
at Angular2App._buildTree (/Users/julien/Documents/projects/bignibou/bignibou-site/bignibou-client/node_modules/angular-cli/lib/broccoli/angular2-app.js:125:27)
at new Angular2App (/Users/julien/Documents/projects/bignibou/bignibou-site/bignibou-client/node_modules/angular-cli/lib/broccoli/angular2-app.js:53:23)
at module.exports (/Users/julien/Documents/projects/bignibou/bignibou-site/bignibou-client/angular-cli-build.js:6:10)
at Class.module.exports.Task.extend.setupBroccoliBuilder (/Users/julien/Documents/projects/bignibou/bignibou-site/bignibou-client/node_modules/angular-cli/node_modules/angular-cli/lib/models/builder.js:55:19)
at Class.module.exports.Task.extend.init (/Users/julien/Documents/projects/bignibou/bignibou-site/bignibou-client/node_modules/angular-cli/node_modules/angular-cli/lib/models/builder.js:89:10)
at new Class (/Users/julien/Documents/projects/bignibou/bignibou-site/bignibou-client/node_modules/angular-cli/node_modules/angular-cli/node_modules/core-object/core-object.js:18:12)
at Class.module.exports.Task.extend.run (/Users/julien/Documents/projects/bignibou/bignibou-site/bignibou-client/node_modules/angular-cli/node_modules/angular-cli/lib/tasks/build.js:15:19)
at /Users/julien/Documents/projects/bignibou/bignibou-site/bignibou-client/node_modules/angular-cli/node_modules/angular-cli/lib/commands/build.js:32:24
at lib$rsvp$$internal$$tryCatch (/Users/julien/Documents/projects/bignibou/bignibou-site/bignibou-client/node_modules/angular-cli/node_modules/angular-cli/node_modules/rsvp/dist/rsvp.js:1036:16)
at lib$rsvp$$internal$$invokeCallback (/Users/julien/Documents/projects/bignibou/bignibou-site/bignibou-client/node_modules/angular-cli/node_modules/angular-cli/node_modules/rsvp/dist/rsvp.js:1048:17)
at /Users/julien/Documents/projects/bignibou/bignibou-site/bignibou-client/node_modules/angular-cli/node_modules/angular-cli/node_modules/rsvp/dist/rsvp.js:331:11
at lib$rsvp$asap$$flush (/Users/julien/Documents/projects/bignibou/bignibou-site/bignibou-client/node_modules/angular-cli/node_modules/angular-cli/node_modules/rsvp/dist/rsvp.js:1198:9)
I am trying to get less css to work with my angular CLI- generated application.
I have tried and configure the plugin as follows in angular-cli-build.js
module.exports = function (defaults) {
return new Angular2App(defaults, {
vendorNpmFiles: [
'systemjs/dist/system-polyfills.js',
'systemjs/dist/system.src.js',
'zone.js/dist/**/*.+(js|js.map)',
'es6-shim/es6-shim.js',
'reflect-metadata/**/*.+(js|js.map)',
'rxjs/**/*.+(js|js.map)',
'@angular/**/*.+(js|js.map)'
],
lessCompiler: {
includePaths: [
'src/assets/styles'
]
}
});
};
Can anyone please help?
The import statement is located in a LESS file to import another LESS file as mentionned in the LESS documentation : import directive feature.
The path of the import is relative to the path declared in the lessCompiler option.
I see. But how do you refer to the main bootstrap.less file from within your index.html?
Your boostrap.less file will be compiled into a boostrap.css file in the dist folder of your project. You have just to follow the path from your index.html file to your boostrap.css file like you do to import a classic stylesheet in an html file.
As LESS errors aren't recovered by the Broccoli stacktrace you don't know what is the problem, so maybe it's not the solution to your problem... but it worked for me.
What you said abvove about the exception being hidden is interesting. Do you or someone else know of any way of having more insight into the underlying exception? I find it impossible to advance blindly. There must be a way of accessing the underlying exception through some debugging...
I know this is not a proper solution to get less' error message - it is rather a quick and dirty hack dumping the entire error object from less to console:
Edit node_modules/angular-cli/lib/broccoli/angular-broccoli-less.js and make the function compile(...) look like this:
compile(fileName, inputPath, outputPath) {
let content = fs.readFileSync(fileName, 'utf8');
return less.render(content, this.options)
.then(output => {
let filePath = fileName.replace(inputPath, outputPath).replace(/\.less$/, '.css');
fse.outputFileSync(filePath, output.css, 'utf8');
}, error => {
console.log(error);
return Promise.reject( error );
});
}
In my case, it revealed that one of the input files contained invalid CSS / less code.
For anyone else trying to use Bootstrap less files to compile, here's how I got it to work. Caveat is that this approach is hard-coded in the dependency. Thanks to @db6edr for pointing out how to display error messages. The error message I got was that Less was trying to compile my Less partials. This workaround forces angular-cli to only compile bootstrap.less.
- Download Bootstrap Source Code
- Move
lessdirectory into/src/css/less - Follow remaining steps below:
Add lessCompiler flag in angular-cli-build.js
//...
lessCompiler: {
compress: true,
paths: [ __dirname + '/src/css/less' ],
},
vendorNpmFiles: [
//...
Modify build() in angular-broccoli-less.js like so
build() {
return Promise.all(this.listEntries().map(e => {
if (path.basename(e.relativePath) != 'bootstrap.less') {
return;
}
let fileName = path.resolve(e.basePath, e.relativePath);
return this.compile(fileName, this.inputPaths[0], this.outputPath);
}));
}
This is inspired by #1150 fix(sass): don't compile partials pull request.
Using db6edr's modification of the compile function, I managed to get more insight into the error/stacktrace.
Here is the error message:
{ [Error: .border-right-radius is undefined]
type: 'Name',
filename: 'input',
index: 31093,
line: 1029,
callLine: NaN,
callExtract: undefined,
column: 2,
extract:
[ '.input-group-btn:last-child > .btn-group:not(:last-child) > .btn {',
' .border-right-radius(0);',
'}' ],
message: '.border-right-radius is undefined',
stack: undefined }
My IDE does warns me of this with the following message:
Element 'border-right-radius' is resolved only by name without using of explicit imports less... (⌘F1) This inspection warns about less elements that are not imported explicitly and resolved through all project less-files only by name. You have no guaranties that these elements will be resolved at the production.
Now what puzzles me is that the following manual compilation using the this command line passes without problem:
lessc src/assets/styles/bootstrap.less dist/assets/styles/style.css
What could cause this inconsistency between lessc and broccoli?
I think I am getting why my use of broccoli-less fails. I need just one less file to be compiled and not all less files within the directory mentioned by path.
If I change the makeBroccoliTree within angular-broccoli-less.js from
exports.makeBroccoliTree = (sourceDir, options) => {
if (less) {
let lessSrcTree = new Funnel(sourceDir, {
include: ['**/*.less'],
allowEmpty: true
});
return new LESSPlugin([lessSrcTree], options);
}
};
to this:
exports.makeBroccoliTree = (sourceDir, options) => {
if (less) {
let lessSrcTree = new Funnel(sourceDir, {
include: ['**/bootstrap.less'],//Pointing to just the one file!
allowEmpty: true
});
return new LESSPlugin([lessSrcTree], options);
}
};
Then a bootstrap.css file is generated properly.
Now I can't obviously fiddle with the node_modules sources. How can I configure this properly?
Closed as this issue was made obsolete by https://github.com/angular/angular-cli/pull/1455.
This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.