Browserify failing with cannot find module "lodash" error for some files - gruntjs

I am running browserify for an app.js located at some path and it fails everytime with cannot find module lodash from [PATH].
Running "browserify:build" (browserify) task
Error: Cannot find module 'lodash' from '/var/lib/jenkins/buildcode/output/mydir/app_store_richUI/cartridge/js'
Warning: Error running grunt-browserify. Use --force to continue.
The [PATH] is same where the app.js file is present. But, if I change the file name to some other js file at same path, it works. So, the scene is that it succeeds for some js file and fails for others at same path.
Can someone suggest something ?
I have the Browserify.js script installed globally.
Browserify.js
module.exports = {
build: {
files: {
'<%= settings["local.build.dir"] %>/output/<%= grunt.config("build") %>/app_eyeconic_richUI/cartridge/static/default/js/eyeconic.app.js':'<%= settings["local.build.dir"] %>/output/<%= grunt.config("build") %>/app_eyeconic_richUI/cartridge/js/app.js'
},
}
}
The path is shown correctly in the logs with other files. It fails only with app.js file

It was a very trivial issue but took quite some time to resolve.
The issue was that the build suite was at a different location than the build source.
The browserify task contained require statements and it searches for modules in the parent directories so it was not able to find the required module.
After copying the build suite at the same path as the source, it worked.
So currently, my gruntfile.js(and other files/folders in the suite), exports and output directory at are same path.

Related

Malformed inclusion path for Meteor Ionic

I am trying to set up my Meteor app with Ionic (using meteoric:ionic). I followed the instructions given (#import statements), also accounting for the known issue with the files being copied only on the second run. Still, I get this error:
=> Errors prevented startup:
While processing files with fourseven:scss (for target web.browser):
/client/style/app.scss: Scss compiler error: File to import:
{}/client/style/.meteor/local/build/programs/server/assets/packages/meteoric_ionic-sass/_ionic
not found in file: /Users/me/repos/brkn/{}/client/style/app.scss
While processing files with fourseven:scss (for target web.cordova):
/client/style/app.scss: Scss compiler error: File to import:
{}/client/style/.meteor/local/build/programs/server/assets/packages/meteoric_ionic-sass/_ionic
not found in file: /Users/me/repos/brkn/{}/client/style/app.scss
=> Your application has errors. Waiting for file change.
Somehow, all paths are prepended by {}/client/style/, which is the location of my app.scss file (can't explain the curly braces).
Can anyone tell what may cause this? How would I fix it?
That repo is no longer maintained.
Please use this official ionic package for meteor meteor add driftyco:ionic

How to use Laravel 5 with Gulp, Elixir and Bower?

I am completely new to all this, 'Bower' and 'Gulp' and Laravel 'Elixir'. I purchased a template that uses them (unfortunately) and now I need some help on how to go about implementing them. I have already installed NPM and Bower. All my packages have been downloaded into:
resources > assets > vendor
This is a screenshot:
Now my question is how do I include all those packages I downloaded in my view? From my understanding I can't run less files directly in the browser, it only runs once due to 'browser caching' or something like that, also the JS scripts are just too many to include in my page.
I want a way where I can work on my files and have them automatically compiled with the compiled files being referenced in my app.php file.
This is a link to the GulpJS file included in my template: http://pastebin.com/3PSN6NZY
You do not need to compile every time someone visits. The compiled sass/js should be run in dev and then the output files referenced.
If you have gulp installed on the project, you should see a gulp.js file in the root of your project. If not, visit here for instructions:
Gulp/Elixer installation and setup
In your gulp.js file:
var elixir = require('laravel-elixir');
elixir(function(mix) {
mix.less([
'app.less',
'normalize.less',
'some-other-less.less',
'and-another.less'
]);
mix.scripts(['app.js', 'some-other-js.js'], 'public/js/output-file.js');
});
While in development you can run gulp watch from the command line to listen for changes and run compile tasks when it hears a change. Then you simply reference the output files in the public directory as you normally would.
If you don't want to listen, you can just run the gulp command for a single once-off task run.
The docs are pretty straight forward and can be found here:
Gulp/Elixer docs

How to set jshint/jsxhint "esnext" option in Atom

I am using Atom's linter, react, and linter-jshint/linter-jsxhint.
In my JSX files, I keep getting the warning
Warning: 'import' is only available in ES6 (use esnext option). (W119)
That's pretty straightforward. I did some searching, and found that this can be set under the jshintConfig option in package.json (when using NPM). My project uses NPM and I have a package.json. I added:
"jshintConfig": {
"esnext": true
}
After that, I did a reload but the warnings persist. I also modified my linter-jshint/linter-jsxhint config in Atom (config.cson) with:
"linter-jshint":
harmony: true
esnext: true
"linter-jsxhint":
harmony: true
esnext: true
And did a reload but that didn't help it either.
So: when using linter-jshint/linter-jsxhint as Atom packages, how to I set the esnext option?
You can create a .jshintrc in your project folder, it will be read by the linter as a json source file.
To use esnext option,
{
"esnext": true
}
You will probably need to reopen your JS file to be able to see the new changes.
First possibility, recommended : you can create a .jshintrc in you home directory and jshint will read it in case there is none in the project directory. You might need to restart Atom after.
Another possibility not recommended : you could also change the config of jshint in Atom and specify the location of your global .jshintrcif for some reason you don't want to put it in your home directory with the flag --config
'linter-jshint':
'jshintExecutablePath': /path/to/jshint --config /path/to/.jshinrc
Run 'which jshint' to find the path.
It is not recommended because every other .jshinrc file (in the project, etc.) will be ignore:
jshint will look for this configuration in a number of locations, stopping at the first positive match:
The location specified with the --config flag
A file named package.json located in the current directory or any parent of the current directory (the configuration should be declared as the jshintConfig attribute of that file's JSON value)
A file named .jshintrc located in the current directory or any parent of the current directory
A file named .jshintrc located in the current user's "home" directory (where defined)
You can use the inline configuration adding this comment in your file .js:
/* jshint esversion: 6 */
http://jshint.com/docs/

How to tell Meteor to ignore `gulpfile.js`

In my meteor project I want to use gulp for tasks meteor doesn't support.
Anyway, the problem is that gulp uses a file called gulpfile.js which is loaded by meteor too and gives errors. So my question is, is there a way to tell meteor to ignore some files ?
UPDATE: One solution I can think of is to put gulpfile.js in the folder packages or public and run gulp as follows
$> gulp --gulpfile packages/gulpfile.js
UPDATE: Just noticed that meteor also seems to load node_modules files :(
Unfortunately, in the current release there's no way to tell Meteor to leave certain files alone, so you cannot have gulpfile.js in your main app folder.
You can, however, leave it in an ignored subfolder. Meteor ignores files and directories that ends with tilde ~, the /tests directory and all private files (those beginning with a dot .). So you can create a folder named for example gulp~ and use it for your gulp-related stuff.
The same holds for node_modules folder, you cannot have it in your application, and you shouldn't. If you want to use a node package in your Meteor application, you can do this with npm package.
Add it to your project with mrt add npm command.
Then create packages.json file with a list of all required packages, for example:
{
"something": "1.5.0",
"something-else": "0.9.11"
}
Afterwards, include your package with Meteor.require:
var something = Meteor.require('something');
If you want to use a node package in your gulp tasks, install it inside the ignored directory.

Setting up auto compile for Stylus

I have installed node.js/stylus/nib on my mac and I can manually compile .styl file to .css on the command line. I also know there is this stylus.middleware() things that keeps coming up when I search for how to setup auto-compiling when the .styl changes, however I have no idea how I am supposed to implement it (I have never used node.js before).
What file do I put that code in?
How do I start this code so it is always run?
I think I am missing a few things on the node side to be able to set this up.
From the command line you can use:
stylus -w folder/
or just for another example:
stylus -w styl/*.styl -o css/
It will watch for changes and compile all *.styl files that live under that folder.
If you installed stylus as a global package (npm install stylus -g) you have a stylus binary on your system.
$ stylus -h
Usage: stylus [options] [command] [< in [> out]]
[file|dir ...]
Commands:
help [<type>:]<prop> Opens help info at MDC for <prop> in
your default browser. Optionally
searches other resources of <type>:
safari opera w3c ms caniuse quirksmode
Options:
-i, --interactive Start interactive REPL
-u, --use <path> Utilize the stylus plugin at <path>
-U, --inline Utilize image inlining via data uri support
-w, --watch Watch file(s) for changes and re-compile
-o, --out <dir> Output to <dir> when passing files
-C, --css <src> [dest] Convert css input to stylus
-I, --include <path> Add <path> to lookup paths
-c, --compress Compress css output
-d, --compare Display input along with output
-f, --firebug Emits debug infos in the generated css that
can be used by the FireStylus Firebug plugin
-l, --line-numbers Emits comments in the generated css
indicating the corresponding stylus line
--include-css Include regular css on #import
-V, --version Display the version of stylus
-h, --help Display help information
This briefly covers some Node basics.
0. Organizing code. It is a convention to put your main Node application code into a file called app.js in the project root.
Inside app.js things are grouped into two general parts:
synchronous initializations: require modules, build directories, read configs, db connections, etc. Things that block, so they must exist or die quickly.
asynchronous app tasks: start server, background processes, auto-compile CSS & JS, routing, i/o, etc. Things that are in the event loop.
1. Compile Stylus to CSS when you build the app. We need to require the stylus module. Usually this is done at the top of the app.js to keep dependencies together.
var stylus = require('stylus');
The first time that Node runs app.js, you need this JS module to build your CSS. This is the basic idea:
stylus.render(stylus-code-string, function(err, css) {
if (err) throw err;
console.log(css);
});
Here is the official Stylus Javascript API.
To use the power of Node, you should read a stylus file using fs module into a buffer, then convert it to a string, and finally pass it into stylus.render(). Then, send the result into a destination file. Since this is part of the build process, it can be synchronous. But this is not really your question...
2. Auto-compile CSS with Stylus as a background process.
This function spawns a child_process that watches a single .styl file and compiles the included .styl files into a .css file. You do not need a module for this, only install the stylus executable so that it runs on the command line. (You have already done this). This example was made with stylus version 0.5.0. Also, the folder paths that you use (ex. build/styles and styles) need to exist.
function watchStyles(sourcefile, destinationfolder) {
var Stylus = child_process.spawn('stylus', ['--sourcemap', '-w', sourcefile, '--out', destinationfolder]);
Stylus.stdout.pipe(process.stdout); // notifications: watching, compiled, generated.
Stylus.stderr.pipe(process.stdout); // warnings: ParseError.
Stylus.on('error', function(err) {
console.log("Stylus process("+Stylus.pid+") error: "+err);
console.log(err);
});
// Report unclean exit.
Stylus.on('close', function (code) {
if (code !== 0) {
console.log("Stylus process("+Stylus.pid+") exited with code " + code);
}
});
}
Next, you need to call this function sometime after you start your app. Pass in your master .styl file as the source. Then the destination directory where you want your CSS to go.
// check that you passed '-w' parameter
if (process.argv[2] && (process.argv[2] == "-w")) {
watchStyles('styles/app.styl', 'build/styles');
}
Start the app by running:
$ node app.js -w
It helps to organize your .styl files under one app.styl so that the contents of your app.styl looks like this:
#import 'layout'
#import 'header'
#import 'main'
#import 'footer'
#import 'modal'
#import 'overrides'
** I end up here yesterday and didn't find the right answer. So this follow up is for anyone else who follows the same path as me... **
I had a problem setting stylus command line up too. I kept trying to install stylus globally
$ npm install -g stylus
and would get errors. I had it working in one project with grunt-contrib-stylus but via command line I wasn't getting anything to work.
Even $stylus --version didn't return anything. I tried to update npm and it broke npm, so I ended up reinstalling node to reinstall npm. Then I was able to do a fresh install of $ sudo npm install -g stylus and could get the --version.
I also had to reinstall grunt and everything else I had installed globally via npm...
First, install stylus locally npm install stylus --save-dev if you haven't.
Create a startup script that builds your stylesheet and rebuilds whenever change detected in your main stylus file:
startup.js
var fs = require('fs')
var stylus = require('stylus')
// Define input filename and output filename
var styleInput = __dirname + '/dev/stylus/main.styl'
var styleOutputFilename = 'main.css'
var styleOutput = __dirname + '/static/' + styleOutputFilename
var stylusPaths = [__dirname + '/dev/stylus', __dirname + '/dev/stylus/libs']
// Build stylesheet on first execute
buildStyles(styleInput, styleOutput, stylusPaths)
// Watch stylus file for changes.
fs.watch(styleInput, function(eventType, filename) {
if (filename) {
buildStyles(styleInput, styleOutput, stylusPaths)
} else {
console.log('no filename found. probably platform doesnt support it.');
}
});
function buildStyles(input, output, paths) {
stylus(fs.readFileSync(input, 'utf-8'))
.set('paths', paths)
.set('include css', true)
.set('watch', true)
.render(function(err, css) {
if (err) throw err;
fs.writeFile(output, css, (err) => {
if (err) throw err;
console.log('👍 Stylesheet built successfully.');
});
});
}
Type node startup.js in the terminal. You will see a message "Stylesheet built successfully." whenever you change your main stylus file.
There is good documentation about stylus javascript api in their website.
OK I edited my answer because you do not want to make a homepage and then connect-assets makes no sense and can not help you... but maybe this,...
http://thechangelog.com/post/3036532096/stylus-expressive-robust-feature-rich-css-language
on that site you find at the bottom a video which shows close to the end how to use stylus via command line...
HTH and sorry for the misunderstanding...

Resources