I was following tutorial that I have found here. Previously the command was running fine, but after some changes when I runnpm run nodemon it gives me error
Here is my package.json
{
"name": "smashing-react-i18n",
"version": "1.0.0",
"description": "",
"main": "dist/bundle.js",
"betterScripts": {
"build": {
"command": "webpack -p",
"env": {
"NODE_ENV": "production"
}
},
"nodemon": {
"command": "nodemon server.js",
"env": {
"NODE_PATH": "src"
}
}
},
Related
I tried to use npm-watch as file watcher to compile scss files. As I run npm run watch, the script runs and does what I expected. But after the run, it immediately ends and does not run again on file change. In other words, it works but it does not watching. It only runs once. What could be the problem?
This is package.json
{
"name": "limitless",
"version": "1.0.0",
"main": "index.js",
"dependencies": {
"autoprefixer": "^10.2.5"
},
"devDependencies": {
"jshint": "^2.10.3",
"node": "14.16.0",
"node-sass": "^5.0.0",
"npm-watch": "^0.11.0",
"uglify-js": "^3.16.1",
"uglifycss": "^0.0.29"
},
"watch": {
"patterns": ["www/scss"],
"extensions": ["scss"],
"delay": "2000"
},
"scripts": {
"watch": "node-sass www/scss/theme.scss www/css/theme.css"
}
}
The problem was that called npm run watch insted of npm-watch.
The solution looks like this:
"watch": {
"compile-css": {
"patterns": ["www/scss"],
"extensions": ["scss"],
"delay": 250,
"runOnChangeOnly": true
},
"compile-js": {
"patterns": ["www/js/src"],
"extensions": ["js"],
"delay": 250,
"runOnChangeOnly": true
}
},
"scripts": {
"compile-css": "npm run scss && npm run minify-css",
"compile-js": "uglifyjs www/js/src/app.js -o www/js/dist/app.min.js & uglifyjs www/js/src/main.js -o www/js/dist/main.min.js",
"scss": "node-sass www/scss/theme.scss www/css/theme.css",
"minify-css": "css-minify -f www/css/theme.css -o www/css",
"js": "npm run uglifyjs ",
"watch": "npm-watch"
},
and so I run npm run watch which calls npm-watch which triggers other scripts if files has been changed.
I am using the --rs option (--rs - Allow to restart with "rs" line entered in stdio, disabled by default)
This is giving me error while running npm run publish :
The package.json file :
{
"name": "nats-test",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"publish": "ts-node-dev --rs --notify false src/publisher.ts",
"listen": "ts-node-dev --rs --notify false src/listener.ts"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"#types/node": "^14.0.23",
"node-nats-streaming": "^0.3.2",
"ts-node-dev": "^1.0.0-pre.51",
"typescript": "^3.9.6"
}
}
Would really appreciate the help.
Try adding the --rs flag to the ts-node-dev command:
ts-node-dev --rs src/publisher.ts
I have a Nodejs project which uses ESLint to keep consistency.
On my Mac machine, I have no troubles all works bur on Windows I got this error
No files matching the pattern "'./*'" were found.
Please check for typing mistakes in the pattern.
My setup for ESLint is
{
"env": {
"es6": true,
"node": true
},
"extends": [
"plugin:prettier/recommended",
"airbnb-base"
],
"plugins": [
"prettier"
],
"globals": {
"Atomics": "readonly",
"SharedArrayBuffer": "readonly"
},
"parserOptions": {
"ecmaVersion": 2018,
"sourceType": "module"
},
"rules": {
"prettier/prettier": "error",
"linebreak-style": "off"
}
}
Package.json
{
"name": "new-architecture-solution",
"version": "1.0.0",
"description": "",
"main": "server.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"prod": "node -r esm server.js",
"dev": "nodemon -r esm server.js",
"debug": "ndb nodemon -r esm server.js",
"lint": "eslint . --ext .js,.jsx --quiet",
"fix": "eslint './*' --fix",
"prettier": "prettier --write src/**/*.{js,css}"
},
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"eslintIgnore": [
"package.json",
"package-lock.json",
"combined.log",
"swagger.json",
"README.md"
],
"lint-staged": {
"./**/*.{js,jsx,ts,tsx,json,css,scss,md}": [
"npm run prettier",
"npm run lint --color",
"npm run fix",
"git add"
]
},
I'm unable to find asolution and I would like to have it work in both my machines
I haven't tried it yet on Windows, but according to this post replacing the single quotes with \" might do the trick. I've tried it on my Mac and it seems to work properly.
Edit: confirmed to work on Windows machines as well.
I have a node js gradle application. I am not sure how to run the application locally.
I have done gradle build (./gradlew) and npm run build(compile). All my dependencies are in the node_modules.
I have a server.ts file having server code apart from the routing.
My package.json-
{
"name": "app",
"version": "..",
"description": "",
"main": "index.js",
"types": "index.d.ts",
"scripts": {
"prepublish": "npm run build",
"build": "tsc",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"async-child-process": "^1.1.1",
..
},
"devDependencies": {
"#types/handlebars": "^4.0.36",
"#types/node": "^8.10.45",
"#types/pg-types": "^1.11.4"
}
}
How to run the project on the server.
tsconfig.json
{
"compilerOptions": {
"outDir": "./build/js/",
"sourceMap": false,
"noImplicitAny": false,
"module": "commonjs",
"declaration":true,
"target": "es2015"
},
"include": [
"src/main/ts/**/*.ts"
],
"exclude": [
"node_modules",
"**/*.spec.ts"
]
}
Node.js will not run ts code. after build it'll js code in dist directory(depends on tsconf.json).
In package.json add below code, run npm run serve to start server.
or go to dist dir and run node server.js.
I have created a sample on GitHub check here
"scripts": {
"serve": "npm run build && npm run start",
"start": "node dist/server.js",
"build": "tsc"
}
I have a package.json that looks something like this:
{
"name": "test",
"version": "0.0.1",
"description": "test test",
"main": "index.js",
"scripts": {
"test": "echo \"No test specified\""
} ,
"devDependencies": {
"gulp": "^3.9.1"
},
"dependencies": {
"bootstrap": "^4.0.0-alpha.5"
}
}
Is it possible to install bootstrap in another directory than "node_modues". If so, how to I write that in the "package.json" file
You can use this code in package.json:
{
"scripts": {
"preinstall": "npm install bootstrap --prefix ./another/"
}
}
your module will be installed in ./another/node_module
NOTE: So you can use another options in this scripts for installing modules as you want.