Grunt not found error when deploying to Heroku - heroku

I'm getting the error below:
remote: sh: 1: grunt: not found
when I'm deploying my code to Heroku server.
My install scripts in package.json is like:
"scripts": {
"postinstall": "grunt heroku:production && bower install",
"test": "mocha",
"start": "node app.js"
}
I set heroku config like
heroku config:set NPM_CONFIG_PRODUCTION=false
Also I made
export BUILDPACK_URL=https://github.com/mbuchetics/heroku-buildpack-nodejs-grunt.git
but nothing has changed. I have grunt and grunt-cli in both dependencies and devDependencies.
So where am I wrong?

Related

npm run dev can not install webpack cli

I have a laravel application with the below config:
laravel version 7.30.4
npm version 6.14.6
node version 12.18.3
When I want run npm run dev, this question is asked:
CLI for webpack must be installed.
webpack-cli (https://github.com/webpack/webpack-cli)
Do you want to install 'webpack-cli' (yes/no):
After typing yes, this error is showed:
Error: Cannot find module 'webpack-cli/package.json'
Require stack:
- C:\Users\SibCo\AppData\Roaming\npm-cache\_npx\5852\node_modules\webpack\bin\webpack.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:965:15)
at Function.resolve (internal/modules/cjs/helpers.js:78:19)
at runCli (C:\Users\SibCo\AppData\Roaming\npm-cache\_npx\5852\node_modules\webpack\bin\webpack.js:50:26)
at C:\Users\SibCo\AppData\Roaming\npm-cache\_npx\5852\node_modules\webpack\bin\webpack.js:139:5
at processTicksAndRejections (internal/process/task_queues.js:97:5) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'C:\\Users\\SibCo\\AppData\\Roaming\\npm-cache\\_npx\\5852\\node_modules\\webpack\\bin\\webpack.js'
]
}
Try installing webpack globally:
npm install -g webpack webpack-cli
If you're using webpack-cli 4 or webpack 5, change webpack-dev-server to webpack serve.
Example:
"serve": "webpack serve --config config/webpack.dev.js --progress"
You might want also to check this comment on GitHub:
NPM package.json scripts are a convenient and useful means to run locally installed binaries without having to be concerned about their full paths. Simply define a script as such:
For webpack-cli 3.x:
"scripts": { "start:dev": "webpack-dev-server" }
For webpack-cli 4.x:
"scripts": { "start:dev": "webpack serve" }
I updated my npm version to v7.11.2 and delete node_modules and ran :
npm install
again, and it worked for me.

/bin/sh: 1: go: not found when pushing to heroku

I'm trying to use React Frontend and Go Backend language.
I have to Go installed locally and I can run commands like go run main.go or go build. But when I try to push to Heroku, I get the following error:
$ rm -rf index && go build -o index
remote: /bin/sh: 1: go: not found
remote: error Command failed with exit code 127.
remote: info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
remote: error Command failed with exit code 127.
remote: info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
remote:
remote: -----> Build failed
This is my package.json:
{
"name": "fullstack-course",
"version": "1.0.0",
"description": "",
"main": "index.go",
"scripts": {
"client": "rm -rf build/ && webpack --env.mode production",
"server": "rm -rf index && go build -o index",
"start": "./index",
"heroku-postbuild": "yarn run client && yarn run server"
},
"engines": {
"node": "10.x",
"npm": "6.9.x",
"yarn": "1.x"
},
"repository": {
"type": "git",
},
"author": "",
"license": "ISC",
"dependencies": {...}
}
Why when running locally it works, but when pushing it to Heroku it fails?
How can I fix this?
Thanks

how to convert angular-cli.json to angular.json

when running "ng test" angular cli throws error
"The test command requires to be run in an Angular project, but a project definition could not be found."
npm install #angular/cli
ng test
wants to convert angular-cli.json to angular.json
Update Angular cli globally and locally, and migrate the old configuration .angular-cli.json to the new angular.json format by running the following:
npm install -g #angular/cli
npm install #angular/cli
ng update #angular/cli

Heroku node_modules not cached

I have toplevel package.json where I set cacheDirectories as per https://devcenter.heroku.com/articles/nodejs-support#custom-caching
"scripts": {
"start": "npm --prefix frontend start && npm --prefix mockserver start",
},
"dependencies": {
},
"devDependencies": {
},
"cacheDirectories": ["frontend/node_modules", "mockserver/node_modules"],
...
So no dependencies in toplevel, but I have frontend/package.json and mockserver/package.json with a lot of dependencies that get installed in their respective node_modules. This is how the respective package.jsons look like (for example mockserver):
"scripts": {
"start": "npm install && npm run build && node dist/server.js",
},
dependencies...
devdependencies...
This works fine and deploys, but it does not cache the the two node_modules defined to be cached.
Here is the output from heroku build:
-----> Creating runtime environment
NPM_CONFIG_LOGLEVEL=error
NPM_CONFIG_PRODUCTION=true
NODE_VERBOSE=false
NODE_ENV=demo
NODE_MODULES_CACHE=true
npm scripts will see NODE_ENV=production (not 'demo')
https://docs.npmjs.com/misc/config#production
-----> Installing binaries
engines.node (package.json): 7.10.0
engines.npm (package.json): unspecified (use default)
Downloading and installing node 7.10.0...
Using default npm version: 4.2.0
-----> Restoring cache
Loading 2 from cacheDirectories (package.json):
- frontend/node_modules (not cached - skipping)
- mockserver/node_modules (not cached - skipping)
-----> Building dependencies
Installing node modules (package.json)
-----> Caching build
Clearing previous node cache
Saving 2 cacheDirectories (package.json):
- frontend/node_modules (nothing to cache)
- mockserver/node_modules (nothing to cache)
-----> Build succeeded!
Just to note that the two node_modules were installed in the previous build but it says (not cached - skipping).
Thanks in advance!
I got the answer here: https://github.com/heroku/heroku-buildpack-nodejs/issues/435
In summary, I should have used heroku-postbuild instead of start script to install custom dependencies. And use start only as application starting command.
Top level package.json
"scripts": {
"heroku-postbuild": "npm --prefix frontend run installAndCompile && npm --prefix mockserver run installAndCompile",
"start": "npm --prefix mockserver start"
},
Subproject's package.json
"scripts": {
"installAndCompile": "npm install && npm run compile"
},

Heroku ruby app - run gulp build process after deploy

I have a ruby application hosted on Heroku, it's a Ruby Sinatra app and I am using gulp to build my sass and coffee files for the client. I have added a postinstall script to my package.json and I have all my gulp dependencies listed but no npm install happens, probably because the app is a ruby application and npm is not on the deploy radar? Here's what my package.json looks like:
"dependencies": {
"gulp": "^3.9.1",
"gulp-coffee": "^2.3.3",
"gulp-filter": "^4.0.0",
"gulp-plumber": "^1.1.0",
"gulp-sass": "^3.0.0",
"browser-sync": "2.16.0"
},
"devDependencies": {},
"scripts": {
"postinstall": "npm install && gulp build"
}
What am I missing? Is it not possible to run npm and ruby on the same container?
I ended up finding the answer here: https://devcenter.heroku.com/articles/using-multiple-buildpacks-for-an-app
What I needed was to add a nodejs buildpack so that npm install would happen along with the postinstall script. Add a node buildpack using the Heroku CLI like this:
heroku buildpacks:add --index 1 heroku/nodejs
I also removed npm install from my postinstall hook because it happens automatically with the node buildpack.

Resources