npm ERR! Missing script: "test" when using github actions - javascript

I wrote a test for my javascript application from the Actions part of git. However, it does not work as expected. Here it is:
# This is a basic workflow to help you get started with Actions
name: Node.js CI Testing
# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the main branch
push:
branches: [ main ]
pull_request:
branches: [ main ]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- name: Use Node.js
uses: actions/setup-node#v2
with:
node-version: "16.x"
- name: Install dependencies
run: npm install --legacy-peer-deps
- name: Run test
run: npm test
However, when I run it, I get the following errors:
Run npm test
npm ERR! Missing script: "test"
npm ERR!
npm ERR! To see a list of scripts, run:
npm ERR! npm run
npm ERR! A complete log of this run can be found in:
npm ERR! /home/runner/.npm/_logs/2022-07-25T23_14_24_295Z-debug-0.log
Error: Process completed with exit code 1.
I searched the internet for how to fix the problem and added the following line to my test file:
- name: Run test
working-directory: ./src
run: npm test
. but without success. Here is my package.json file:
{
"name": "hydrogen",
"version": "1.0",
"scripts": {
"start": "vite",
"dev": "vite",
"build": "vite build",
"serve": "vite preview"
},
"devDependencies": {
"autoprefixer": "^10.4.2",
"postcss": "^8.4.5",
"tailwindcss": "^3.0.18",
"vite": "^2.7.13",
"vite-plugin-solid": "^2.2.5"
},
"dependencies": {
"#tailwindcss/forms": "^0.4.0",
...
"solid-js": "^1.3.3"
}
}

That is happening because when Github Actions is trying to run this part of the worflow:
name: Run test
run: npm test
npm does not find a "test" script in your package.json:
"scripts": {
"start": "vite",
"dev": "vite",
"build": "vite build",
"serve": "vite preview"
},
So if you don't have tests in your project you can get rid of "run: npm test" in your workflow or add a "test" script in your package.json:
"scripts": {
"start": "vite",
"dev": "vite",
"build": "vite build",
"serve": "vite preview",
"test": "echo \"Error: no test specified\" && exit 1"
},

Related

Npm not running in terminal vite

What I typed: Npm run dev
Error:
npm ERR! Missing script: "dev"
npm ERR!
npm ERR! To see a list of scripts, run:
npm ERR! npm run
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\andre\AppData\Local\npm-cache\_logs\2021-11-12T04_58_51_898Z-debug.log
Json:
{
"name": "port",
"version": "0.0.0",
"scripts": {
"dev": "vite",
"build": "vite build",
"serve": "vite preview"
},
"devDependencies": {
"vite": "^2.6.4"
},
"dependencies": {
"three": "^0.134.0"
}
}
If you could help thank you and if not thank you for reading this and taking your time out of your day
Goto you project directory by cd your-project-name.
run npm run dev command and try again (In your npm command "N" is capital).
and if not work please check below link (please refer green tick answer) :
How to resolve npm run dev missing script issues?

setting start scripts in package.json

locally, i start my app using the following commands:
cd react-web
sudo npm run postinstall
export REACT_APP_CUSTOMER_ENVIRONMENT=envvariable
npm start
So, now i want to push this live through heroku. BUT, i need to set the start scripts in my package.json
so i have two package.json, one in the root directory, and one in react-web.
in the root directory, i wrote this start-script:
"scripts": {
"test-web": "cd react-web && npm test && cd ..",
"test": "npm run test-web",
"start": "cd react-web && export REACT_APP_CUSTOMER_ENVIRONMENT=gianlucaherokutest && npm start"
},
and in the react-web package.json, this:
"scripts": {
"start": "node checkEnvironmentForBuild && react-app-rewired start",
"build": "node checkEnvironmentForBuild && react-app-rewired build",
"deploy": "aws s3 sync build/ s3://YOUR_S3_DEPLOY_BUCKET_NAME --delete",
"postdeploy": "aws cloudfront create-invalidation --distribution-id YOUR_CF_DISTRIBUTION_ID --paths '/*' && aws cloudfront create-invalidation --distribution-id YOUR_WWW_CF_DISTRIBUTION_ID --paths '/*'",
"postinstall": "npm link ../shared",
"test": "node checkEnvironmentForBuild && react-app-rewired test",
"eject": "react-scripts eject"
},
can someone give me some advice on why it isn't working? When I run the app using everything above, it gives me this error:
2021-04-19T21:12:11.796818+00:00 app[web.1]: FATAL ERROR: MarkCompactCollector: young object promotion failed Allocation failed - JavaScript heap out of memory
any ideas?

Angular NPM Run Prod: Error npm ERR! missing script: prod

I am running npm with a new Angular Project and receiving error below. How can fix this?
npm ERR! missing script: prod
npm ERR! A complete log of this run can be found in:
npm ERR! C:\..2020-11-19T05_27_19_941Z-debug.log
This means you don't have a configuration for prod in your scripts. Basically to run any angular project you need to make sure the scripts or commands are defined inside your package.json. Most angular projects will have a script configuration like below
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
So, you can run either ng serve or npm start in your command to start the application.
This is because you don't have the script : prod in your package.json file. If you want to run the angular project, you can use ng serve or npm run start

How do I setup live code reload with featherjs?

How do I setup live code reload, kind of like meteor, with featherjs?
Nodemon installs automatically via CLI. To run it just type npm run dev.
Step 1. Install nodemon in your app directory:
npm install --save-dev nodemon
Step 2. Add the following to your package.json file, in the scripts section:
...
},
"scripts": {
"test": "npm run eslint && npm run mocha",
"dev": "./node_modules/nodemon/bin/nodemon.js src/",
"eslint": "eslint src/. test/. --config .eslintrc.json",
"start": "node src/",
"mocha": "mocha test/ --recursive"
}
...
Step 3. Run the script using:
npm run dev

How do I add a custom script to my package.json file that runs a javascript file?

I want to be able to execute the command script1 in a project directory that will run node script1.js.
script1.js is a file in the same directory. The command needs to be specific to the project directory, meaning that if I send someone else the project folder, they will be able to run the same command.
So far I've tried adding:
"scripts": {
"script1": "node script1.js"
}
to my package.json file but when I try running script1 I get the following output:
zsh: command not found: script1
Does anyone know the steps necessary to add the script mentioned above to the project folder?
*Note: the command can not be added to the bash profile (cannot be a machine specific command)
Please let me know if you need any clarification.
Custom Scripts
npm run-script <custom_script_name>
or
npm run <custom_script_name>
In your example, you would want to run npm run-script script1 or npm run script1.
See https://docs.npmjs.com/cli/run-script
Lifecycle Scripts
Node also allows you to run custom scripts for certain lifecycle events, like after npm install is run. These can be found here.
For example:
"scripts": {
"postinstall": "electron-rebuild",
},
This would run electron-rebuild after a npm install command.
I have created the following, and it's working on my system. Please try this:
package.json:
{
"name": "test app",
"version": "1.0.0",
"scripts": {
"start": "node script1.js"
}
}
script1.js:
console.log('testing')
From your command line run the following command:
npm start
Additional use case
My package.json file has generally the following scripts, which enable me to watch my files for typescript, sass compilations and running a server as well.
"scripts": {
"start": "concurrently \"sass --watch ./style/sass:./style/css\" \"npm run tsc:w\" \"npm run lite\" ",
"tsc": "tsc",
"tsc:w": "tsc -w",
"lite": "lite-server",
"typings": "typings",
"postinstall": "typings install"
}
Steps are below:
In package.json add:
"bin":{
"script1": "bin/script1.js"
}
Create a bin folder in the project directory and add file runScript1.js with the code:
#! /usr/bin/env node
var shell = require("shelljs");
shell.exec("node step1script.js");
Run npm install shelljs in terminal
Run npm link in terminal
From terminal you can now run script1 which will run node script1.js
Reference: http://blog.npmjs.org/post/118810260230/building-a-simple-command-line-tool-with-npm
Lets say in scripts you want to run 2 commands with a single command:
"scripts":{
"start":"any command",
"singleCommandToRunTwoCommand":"some command here && npm start"
}
Now go to your terminal and run there npm run singleCommandToRunTwoCommand.
Suppose I have this line of scripts in my "package.json"
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"export_advertisements": "node export.js advertisements",
"export_homedata": "node export.js homedata",
"export_customdata": "node export.js customdata",
"export_rooms": "node export.js rooms"
},
Now to run the script "export_advertisements", I will simply go to the terminal and type
npm run export_advertisements
Example:
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build --prod",
"build_c": "ng build --prod && del \"../../server/front-end/*.*\" /s /q & xcopy /s dist \"../../server/front-end\"",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
As you can see, the script "build_c" is building the angular application, then deletes all old files from a directory, then finally copies the result build files.

Categories

Resources