Check jshint errors before npm run build - javascript

I have setup webpack using npm. I installed jshint using npm install jshint --save-dev.
Now if I run command jshint assets/js/index.js i get errors.
I want to check the errors on npm run build

You can change your build script in the package.json in the way to run lint and then if it successful run build. See example
{
...
"scripts": {
"build": "npm run lint && your_build_command",
"lint": "jshint assets/js/index.js"
}
...
}

Related

Accessing the script of package.json of a npm package from our project package.json file

I created a tool and registered it on npmjs.com named Yattex. It script looks something like this
`
"scripts": {
"clean:reports": "rm -R -f cypress/reports && mkdir cypress/reports && mkdir cypress/reports/mochareports ",
"pretest": "npm run clean:reports",
"scripts": "cypress run",
"combine-reports": "mochawesome-merge cypress/reports/mocha/*.json > cypress/reports/mochareports/report.json",
"generate-report": "marge cypress/reports/mochareports/report.json -f report -o cypress/reports/mochareports -- inline",
"posttest": "npm run combine-reports && npm run generate-report",
"yattex-tool": "node yattex-tool",
"decorator": "node yattex-tool/test-decorators",
"test": "npm run decorator && npm run scripts || npm run posttest || npm run yattex-tool"
},
`
Now, in another project i installed the package and now i dont know what to write in scrips(test) to run the above test command which is in the node_modules/yattex/package.json file
I tried yattex and node node_modules/yattex/package.json
But it doesn't work. I'm a newbie and i cant find any solution...
If you add a property
"workspaces": ["./node_modules/yattex"]
to the package.json file in your other project, then npm test --workspaces will execute the tests both in your other project and in the yattex project (which is a "workspace" as explained on the npm help run page).
If you want to run only the tests for yattex, use npm test --workspace=./node_modules/yattex.

"npm run dev" Command Doesn't Work - Giving "missing script: dev" error

I was trying to run this SVELT GitHub repo on local server:
https://github.com/fusioncharts/svelte-fusioncharts
I tried to launch it with "npm run dev" command. But I am seeing this error:
npm ERR! missing script: dev
I have tried to fix the issue by setting 'ignore-scripts' to false with this command:
npm config set ignore-scripts false
But it doesn't work.
How can I fix the issue?
npm ERR! missing script: dev means you are there isn't a script having dev. You are likely running on an incorrect directory.
Fusion charts seem to work with svelte codesandbox.
npm ERR! missing script: dev means it cannot find a script called dev inside package.json.
That makes sense!
It looks at the package.json inside the svelte-fusioncharts repo. In that file, there is a scripts property.
Notice how that property looks as follows:
"scripts": {
"build": "rollup -c",
"prepublishOnly": "npm run build"
}
It does not contain a dev script. That’s why it says there’s a missing script. Other commands will work, like npm run build or npm run prepublishOnly.
Md. Ehsanul Haque Kanan,
"scripts": {
"build": "cross-env NODE_ENV=production webpack",
"dev": "webpack-dev-server --content-base public" }
The above is the script from the examples folder in the repo: https://github.com/fusioncharts/svelte-fusioncharts/blob/develop/examples/package.json
You have missed out on the "dev" script in your package.json file.
Please check the "package.json" file in your project and just add the "dev" script as in the repo link and then retry.
Alright. I have fixed the issue. I just go inside examples folder. Then I run the following commands:
npm install
npm run dev
I had the same problem.
It is due to changes in script object in package.json by me. I had installed nodemon and to run the code, I changed the script lifecycle events start and dev in package.json to run the code via nodemon.
But even after installing nodemon, it was not reflecting in devDependencies, so I made manual entry in package.json with its version seeing from package-lock.json.
"devDependencies": {
"nodemon":"^2.0.15"
}
Making this arrangement, my code started as expected.
So, check your recent npm package installation and verify its reflection in devDependencies or dependencies in package.json.

Redux - npm run dev

After executing the command
npm i --save-dev react-redux#5.0.2 redux#3.6.0
and then
npm run dev
is showing the following error.
enter image description here
--save-dev Is to save a dependancy as a devDependancy.
Which doesn't mean that you can do npm run dev
You need to modify your package.json file
"scripts": {
"dev": "xxxx"
}

Apply changes from linked npm modules without rebuilding

My webapp consists of two modules from separate git repos, with the following directory structure:
webapp/module1
webapp/module2
module1 depends on module2, so I've added the link:
cd webapp/module1
npm link ../module2
The module1 is main module, so I'm running webapp using npm start from there:
cd webapp/module1
npm start
start is configured in module1's package.json as follows:
{
"scripts": {
...
"start": "webpack-dev-server --open --progress --colors & npm run build:css -- -w",
"build:css": "node-sass src/style/main.scss dist/webpage.min.css --output-style compressed"
}
}
The problem is when I make a change to module2 source code editing its javascript sources - the change is not applied immediately to the running webapp instance. I need to execute npm run build manually:
cd webapp/module2
npm run build
build is configured in module2's package.json as follows:
"build": "cross-env WEBPACK_ENV=prod && npm run v:patch && webpack"
Only after this step the changes are applied to the webapp. Is there a way to get such changes to be applied automatically? I'm using npm version 5.6.0.

Using babel-cli locally

Is there a way to use the babel client without installing it globally?
So rather than this
npm install -g babel-cli
I'd like to do this
npm install babel-cli --save-dev
Any local package's binary can be accessed inside npm scripts as if it was installed globally:
// package.json
{
"scripts": {
"build": "babel ..."
}
}
If you want to execute the binary on the command line, you can use a relative path to node_modules/.bin/:
$ node_modules/.bin/babel ...
This is related to first example: node_modules/.bin/ is simple added to the PATH of the environment the npm scripts are executed in.
you can put something like this:
{
"scripts": {
"start": "babel-node test.js"
}
}
in your package.json where test.js is a script which you want to run. Now you can run it with npm start command
Yes, you could install locally and run from node_modules:
./node_modules/.bin/babel
If you have a local package.json you could add an NPM script to simplify the command, since NPM scripts run with ./node_modules/.bin on the PATH:
"scripts": {
"babel": "babel ...",
}
To run from any directory under package.json:
$ npm run babel
If you just want to run test with command "npm test testFile.js". This is my package.json:
"scripts": {
"build": "babel-node",
"test": "node_modules/.bin/babel-node"
}

Categories