Run lessc through Node - not Bundler - bundler

Got a bit of a pickle of a question - I'm sure fairly straight forward if I just knew the correct way to ask Google.
I've been getting the hang of LESS lately and originally installed it globally through NPM, i.e. npm install lessc -g to use with an initializer project - running lessc less/style.less style.css like a champ before I deploy it off my local computer.
Loving it - working great - decide to use LESS with a separate rails project - add the gem 'less-rails' to the project - bundle install - get it rolling and working smoothly.
Unfortunately now that I've gone back to my initializer project - lessc less/style.less style.css throws an error message that references RVM and Bulder.
Eventually I found a workaround by installing LESSC locally with npm install lessc -g and running node_modules/less/bin/lessc less/style.less style.css but this is a pain.
So: How do I get LESSC back to working exclusively with Node and ignoring all that RVM / Ruby / Bundler crap?
Thanks!

Ok - I was able to do this by adding a variable to my .bash_profile file in my user directory that pointed at the global node installation of LESS.
Basically adding
export lessc=~/.npm/less/1.3.0/package/bin/lessc
to .bash_profile or .profile or .bashrc in your user directory. And running source ~/.bash_profile.

Related

Do NPM packages have to be installed globally to access their functionality via the command line?

I am having trouble understanding how the -g flag works in NPM. Specifically I'm struggling to understand how it relates to command-line functionality exposed by NPM modules.
I assumed that the difference between installing a package locally and globally was simply that a local package would not be available outside of the particular project. And of course that a globally installed package would be available in any project. I'm from a Rails background so this for me would be similar to installing a gem into a particular RVM versus installing it into the global RVM. It would simply affect which places it was available.
However there seems to be more significance than just scope in NPM. For packages that have command-line functionality, like wait-on, the package (as far as I can tell) is not available on the command line unless it's installed globally.
Local install doesn't make the command-line functionality available:
$ npm install wait-on
$ wait-on
=> -bash: /usr/local/bin/wait-on: No such file or directory
Global install does expose the command-line functionality
$ npm install wait-on -g
$ wait-on
=> Usage: wait-on {OPTIONS} resource [...resource]
Description:
wait-on is a command line utility which will wait for files, ports,
sockets, and http(s) resources to become available (or not available
using reverse flag). Exits with success code (0) when all resources
are ready. Non-zero exit code if interrupted or timed out.
Options may also be specified in a config file (js or json). For
example --config configFile.js would result in configFile.js being
required and the resulting object will be merged with any
Can you expose the command-line functionality using a local install?
Is it possible to install locally but also get the command line functionality? This would be very helpful for my CI setup as it's far easier to cache local modules than global modules so where possible I'd prefer to install locally.
If you are using npm 5.2.0 or later, the npx command is included by default. It will allow you to run from the local node modules: npx wait-on
For reference: https://www.npmjs.com/package/npx
I think you can access locally installed modules from the command line only if you add them to your "scripts" section of your package.json. So to use the locally installed version of wait-on, you can add an entry in "scripts" section of package.json like so "wait-on": "wait-on". Then to run it, you would have to do npm run wait-on. You can also do "wo": "wait-on" and then do npm run wo basically meaning what comes after the run is the script entry. In node_modules, there is a .bin folder and inside of this folder is all the executables that you can access this way.
Installing locally makes the package available to the current project (where it stores all of the node modules in node_modules). This is usually only good for using a module like so var module = require('module'); or importing a module.
It will not be available as a command that the shell can resolve until you install it globally npm install -g module where npm will install it in a place where your path variable will resolve this command.
You can find a pretty decent explanation here.
It is also useful to put commands in the scripts block in package.json as it automatically resolve local commands. That means you could have a script that depended on a package without having an undocumented dependency on the same.
If you need to run it locally on cmd, you have to go inside the node_modules and run from the path.

I didn't run "Yarn add react-native" to a folder, will I run into issues when starting a project? I'm a noob and am just starting out

I used the CLI to install React Native, Node and Python but was not aware if I needed to save it to a file first.
I ran the yarn command:
➜ ~yarn add <package>
I would get this warning message when running yarn check:
➜ ~ yarn check
warning package.json: No license field
warning No license field
warning "jest-haste-map#fsevents#node-pre-gyp#^0.12.0" could be deduped from "0.12.0" to "node-pre-gyp#0.12.0"
Questions:
1. Do I only ~ yarn add when I start a project?
2. Since I've installed python, node, and react-native without creating a project folder will I run into issues down the road?
3. Do I add the json file with the licenses manually when starting a project with yarn?
4. Am I hopeless? lol
I've tried uninstalling and reinstalling from yarn and updating yarn. Also, I've tried installing python and node from Homebrew to see if that changes anything.
Below is a log of the output from the CLI after running ~ yarn check
Last login: Sat Aug 24 02:21:38 on ttys001
➜ ~ yarn check
yarn check v1.17.3
warning package.json: No license field
warning No license field
warning "jest-haste-map#fsevents#node-pre-gyp#^0.12.0" could be deduped from "0.12.0" to "node-pre-gyp#0.12.0"
success Folder in sync.
✨ Done in 1.99s.
Solution I figured it out! So after poking around I realized that once I started a project I had a yarn.lock and package.json file one level up in the directory where the file was located. What I did was I deleted yarn.lock and package.json associated with the folder in the directory. After that was complete I then went into my project and installed the correct packages.
You're not hopeless. This project may be, you've bitten off waaaay more than you can chew yet.
To answer your main question:
yarn add and it's cousin npm install will install the thing you tell them to in the node_modules folder in the directory you run the command in. The reason it's yelling at you is because usually you'll want to save the thing you installed as a dependency of your project, and you can't do that without a package.json file. You should run npm init to set up the package.json file for your project, then running yarn add will actually save it to the dependencies list so that you have a reproducible. If you have a package.json file already, it sounds like you maybe created it by hand (since it's missing a license field?) rather than have npm set it up for you, which is a bad idea.
Two more things:
React Native is awesome! ...But, it's a tool for people who already have good familiarity with Javascript command line/tooling/ecosystem/coding/React to build mobile apps. It is a lousy choice for a first project if you're just getting started with programming. Building a webpage with React is a lot easier, but even that may be too much.
If you really want to build a React Native app and you just can't wait look at this to get started.
But seriously, learn Javascript then npm then yarn then React then React Native. In that order.

Installing the correct environment for Angular with Compass and all other Node dependencies

I am just trying to make a local development environment that isn't on my work computer, and I keep getting an error:
Warning: Errno::ENOENT on line 441 of /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/pathname.rb: No such file or directory - /Users/johnpett/Desktop/Node/app/bower_components
Run with --trace to see the full backtrace Use --force to continue.
I have installed all the Ruby parts and Yeoman to build the app scaffold, but I can't seem to run the 'grunt server' command without throwing up this error.
The error is quite clear, a grunt-plugin require that file...
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/pathname.rb
Anyway ruby components are needed usually if you plan to use compass, if not, you can comment the "compass" sub-task in the "server" task in Gruntfile.js
Your folder was surely not called bower_components at that time. I guess you used yeoman.
In your compass task config you should have modified bower_components.

Running node.js packages on Windows outside the bin dir

I'm using the Node.js for Windows package (currently 0.4.2) downloaded from here:
http://www.rafaljonca.org/d/nodejs-windows
It works great - I can install packages with npm, and run packages like node-inspector, express, etc. The problem is that I can only run those packages if I'm in the bin directory of the distro. I run the setenv.cmd file, which adds bin to the path, but attempting to actually invoke a package (like install another package using npm) when I'm not in the bin path results in the following exception.
Error: Cannot find module '/npm '
at Function._resolveFilename (module.js:299:11)
at Function._load (module.js:245:25)
at Array.<anonymous> (module.js:402:10)
at EventEmitter._tickCallback (node.js:108:26)
I've tried setting the NODE_PATH environment variable to my node package dir, but that doesn't. help.
Though the question is 4 months old I've run into the same issue recently, so hopefully this is still useful.
There is a bug in the runnode.cmd file - there are 2 spaces at the end of line 4, after 'convArg=%%i'. If you remove them, the script will work.

Hotcocoa installation path error

I have installed MacRuby 0.6 and then the hotcocoa gem from Github. However, when I try to create a hotcocoa application with eg.
hotcocoa demoapp
I get the error
-bash: /usr/local/bin/hotcocoa: No such file or directory
Typing 'which hotcocoa' results in
/usr/bin/hotcocoa
Other online documentation seems to suggest that this ought to have been installed to /usr/local/bin so I am confused (a) how it ended up here and (b) why it can't be found even though both locations are in my PATH
I installed hotcocoa with:
sudo macgem install hotcocoa
I had previously done a gem install by mistake but I uninstalled that when I realised I should be using macgem instead.
echo $PATH
/opt/local/bin:/opt/local/sbin:/usr/local/git/bin:/usr/local/bin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/libexec
Any thoughts?
Addendum
As an experiment, I also changed the order of the items in the PATH and it can now find hotocoa. My PATH is now...
/usr/local/git/bin:/opt/local/bin:/opt/local/sbin:/usr/bin:/usr/local/bin:/bin:/sbin:/usr/sbin:/usr/libexec
..with /usr/bin listed earlier than /usr/local/bin
Of course this still doesn't explain why it couldn't find it before (all the path elements seem to exist) or why it was installed there.
Thank you for sharing your experience! I've been struggling with the same set of issues and outcomes for a while. Path order was a non-issue in my case.
It appears that for MacRuby 0.7.1 (installed via RVM) with hotcocoa (installed via sudo macgem), the use of 'sudo' is required to avoid potential load errors.
For example:
(1) keying in 'hotcocoa mydemo', displays the 'Could not find RubyGem hotcocoa (>= 0) (Gem::LoadError)' message on my box. Whereas, if I key in 'sudo hotcocoa mydemo', no load error occurs and, Rakefile, config, lib, and resources items can be listed in the 'mydemo' directory.
(2) keying in 'macrake' results in rake aborted: no such file to load -- hotcocoa/application_builder. Whereas, keying in 'sudo macrake' displays the Mydemo window and its 'Hello from HotCocoa' message.
I actually found that installing hotcocoa without the sudo command worked.

Resources