Grunt will simply not install on my Win 8.1 machine - gruntjs

I made a folder g in root(C:/) in where I try to install Grunt via npm.
I sucessfull made: npm install -g grunt-cli.
I configured package.json to this:
{
"name": "testing",
"version": "0.0.0",
"dependencies": {
"grunt": "~0.4.5" },
"description": "testing",
"main": "index.html",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"devDependencies": {
"grunt": "^0.4.5"
}
}
So good so far.
BUT: When I try to install Grunt: npm install grunt --save-dev and modules(plugins) then I run into this error: npm WARN package.json testing#0.0.0 No repository field...
I use GitHub where I've forked Grunt and Grunticon.
Then I can't succed with nothing towards installing Grunt...
Any good clues and help in solving this?

Okay, I think I see the problem clearly now. Here are some instructions for getting Grunt running, try to follow these exactly, do not create any other folders as it could cause issues for Grunt or Node.
Create a folder for your project, this can be anywhere on your system.
Save the file you have above as package.json in that folder.
Now install the global Grunt CLI
~$ npm install -g grunt-cli <-- Note this is "grunt-cli" NOT "grunt"
Then go to the new directory you created and run this command:
~/new-directoty$ npm install
This will install the Grunt runtime locally for your project because it is specified in package.json
Create a very simple config file in the new directory and name it Gruntfile.js:
module.exports = function(grunt) {
grunt.initConfig({ /* your config will go in here */ });
/* multi-task definitions go here */
};
Now try to run Grunt just to test that it works:
~/new-directory$ grunt
After that you are ready to start adding plugins, but that's a bigger topic. Good luck.

Related

Husky prepare script failing firebase function deployment

I have installed husky in my npm project as a prepare script like below
{
"name": "functions",
"scripts": {
"build": "tsc",
"start": "npm run serve",
"deploy": "firebase deploy --only functions",
"prepare": "husky install functions/.husky"
}
"dependencies": {
"firebase-admin": "^11.4.1",
"firebase-functions": "^4.1.1",
},
"devDependencies": {
"husky": "^8.0.2",
"typescript": "^4.9.4"
}
}
husky is declared as devDependencies as this npm module is only required while local development and has no need in runtime app.
So when I run npm run deploy, I get the below error
i functions: updating Node.js 16 function funName(us-central1)...
Build failed:
> prepare
> husky install functions/.husky
sh: 1: husky: not found
npm ERR! code 127
npm ERR! path /workspace
npm ERR! command failed
npm ERR! command sh -c -- husky install functions/.husky
This error clearly states that husky is not installed.
One possible solution is to create a prepare.js script which checks if the script is running while in local development or in the firebase server(to prepare the project) and then conditionally run the husky npm module command
I just ran into this exact same issue but with tsc. I'm not sure why, but the prepare script is also run in the cloud function (not just locally) while deploying. However, considering you likely have the node_modules directory in the functions.ignore list in the firebase.json, the node_modules directory doesn't get uploaded as part of the deployment and so the husky package isn't visible to the script when it gets run in the cloud function environment.
You likely don't need the husky script to be run in the function environment either way, so you can add a condition to check for an environment variable that is usually set in the function environment (I am using the GOOGLE_FUNCTION_TARGET environment variable in my case), and only run the command if that environment is not set. You also need to wrap this in a bash script instead of adding it inline in the package.json because of how the prepare script is run.
For example, here's the content of my scripts/prepare.sh file.
#!/bin/bash
set -o verbose
# Only run if the GOOGLE_FUNCTION_TARGET is not set
if [[ -z "$GOOGLE_FUNCTION_TARGET" ]]; then
npm run build
fi
Then I use it in my package.json prepare script:
// ...
"prepare": "./scripts/prepare.sh",
// ...
There's potentially a better solution to this, but this is how I got it to work for me. Hope this helps!
This SO answer is spot on and uses bash script. I used the same concept mentioned in the answer to write the prepare script in js in scripts/ folder with the name of prepare.mjs
"use-strict";
import * as path from "path";
import { fileURLToPath } from "url";
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
// Firebase sets the GOOGLE_FUNCTION_TARGET when running in the firebase environment
const isFirebase = process.env.GOOGLE_FUNCTION_TARGET !== undefined;
if (!isFirebase) {
process.chdir("../"); // path where .git file is present. In my case it was ..
const husky = await import("husky");
husky.install("functions/.husky"); // path where .husjy config file is present w.r.t. .git file
}
And in my package.json I have used the above script as follows
{
"name": "functions",
"scripts": {
"build": "tsc",
"start": "npm run serve",
"deploy": "firebase deploy --only functions",
"prepare": "node ./scripts/prepare.mjs"
}
"dependencies": {
"firebase-admin": "^11.4.1",
"firebase-functions": "^4.1.1",
},
"devDependencies": {
"husky": "^8.0.2",
"typescript": "^4.9.4"
}
}
This uses the environment variable(GOOGLE_FUNCTION_TARGET) documented by the Google at the doc

How to add localserver to existing project in webpack?

I use a starter for Mithril.js that run well (starter on github). To run the app, I write in the CLI: "npm start".
After adding to my project Firebase, the app needs localserver. I tryed many other starters and all failed in a second run or in first run.
I try to use local-web-server in webpack (package.json) in the following way:
"start": "webpack -d --watch ws --spa public/index.html",
but it gives error.
How can I add to the starter web-server?
try installing
npm install webpack-dev-server --save-dev
add this setting to webpack.config.js
devServer: {
contentBase: path.join(__dirname, "dist"),
compress: true,
port: 9000
}
and contentBase add your file path

package.json ignored during meteor build

I upgraded my meteor project to version 1.5.1. It runs fine when I just start it with the meteor run command. But as soon as I build it, it will compain about missing babel-runtime. It seems that it ignores my package.json file in the project folder. And thus babel-runtime is not being installed when running meteor npm installafter having built the project
Content of my package.json
{
"dependencies": {
"babel-runtime": "^6.26.0",
"bcrypt": "^1.0.3"
}
}
Content of package.json inside the bundle/programs/server/ folder after running meteor build
{
"name": "meteor-dev-bundle",
"version": "0.0.0",
"dependencies": {
"meteor-promise": "0.8.4",
"fibers": "1.0.15",
"promise": "7.1.1",
"underscore": "1.5.2",
"source-map-support": "https://github.com/meteor/node-source-map-support/tarball/1912478769d76e5df4c365e147f25896aee6375e",
"semver": "4.1.0",
"node-gyp": "3.6.0",
"node-pre-gyp": "0.6.34"
},
"devDependencies": {
"eachline": "https://github.com/meteor/node-eachline/tarball/ff89722ff94e6b6a08652bf5f44c8fffea8a21da",
"chalk": "0.5.1"
},
"scripts": {
"install": "node npm-rebuild.js"
}
}
Am I missing something here? Of course I ran meteor npm install --save babel-runtime many times...
Well, the solution would be to install npm modules before building production bundle (assuming you already have babel-runtime in your package.json):
cd <path_to_project>
meteor npm install
meteor build ...
Built bundle's package.json won't have babel-runtime, but it will be included in bundle from node_modules folder.
Added:
Don't forget that you still have to do npm install in your deployed bundle, as usual.

SASS TASK in GRUNT ERROR: you need to have Ruby and Sass installed

I trying to use grunt-contrib-sass and receive an error:
You need to have Ruby and Sass installed and in your PATH for this task to work.
But i'm sure that i already install Ruby and Sass.
I have check it with below command
ruby -v and receive 1.9.3p545
sass -v and receive 3.4.5
So that make me sure i already install Ruby and Sass.
But when i use
grunt sass
I receive that error.
Please help me and i really appreciate it.
Sorry my English is not so good.
This is my package.json
{
"name": "TEST",
"version": "0.0.1",
"dependencies":
{
"grunt": "~0.4.5",
"grunt-contrib-sass": "~0.8.1"
}
}
and this is gruntfile.js
module.exports = function(grunt)
{
grunt.loadNpmTasks('grunt-contrib-sass');
grunt.initConfig
({
sass:
{
dist:
{
options:
{
style: 'compressed'
},//options
files:
{
'css/style.css': 'component/sass/style.scss'
}//files
}//dist
}//sass
})//initConfig
}//exports
Run gem install sass and everything should be fine. Because a fresh install fixes the installation paths and bindings.

Grunt concat failing with "Unable to find local grunt"

I have installed Grunt like so `npm install -g grunt-cli successfully.
I have also installed the grunt-contrib-concat libary succesfully like so: npm install grunt-contrib-concat --save-dev
I have created a package.json:
{
"name": "my-project-name",
"version": "0.1.0",
"devDependencies": {
"grunt": "~0.4.1",
"grunt-contrib-jshint": "~0.1.1",
"grunt-contrib-nodeunit": "~0.1.2"
}
}
and a Gruntfile.js:
module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
concat: {
options: {
separator: ';'
},
dist: {
src: ['src/init.js', 'src/Game.js', 'ui/Ui.js', 'ui/AddBTS.js', 'ui/Toolbar.js'],
dest: 'built.js'
}
}
});
grunt.loadNpmTasks('grunt-contrib-concat');
};
Now when I run grunt concat I get the following error:
Fatal error: Unable to find local grunt.
If you're seeing this message, either a Gruntfile wasn't found or grunt
hasn't been installed locally to your project. For more information about
installing and configuring grunt, please see the Getting Started guide:
This is my first time using Grunt and I've been trying to solve this problem for over 2 hours now. Please could someone help me and advise what I've not set up correctly.
Thanks in advance!
It's likely that Grunt is not installed locally in your project folder (which is different than grunt-cli). You have it in your package.json so try doing npm install or alternately npm install grunt.
For more information see the getting started page:
Note that installing grunt-cli does not install the grunt task runner! The job of the grunt CLI is simple: run the version of grunt which has been installed next to a Gruntfile. This allows multiple versions of grunt to be installed on the same machine simultaneously.

Resources