how to run the preact application using webpack-dev-server - node.js

Please teach me the solution how to run the preact application using webpack-dev-server.
I am getting the following errors in "npm run start"
package.json file
npm run start

I fixed my error by changing "start:root" and "start:query" as follows.
"start:root": "SET NODE_ENV=development && webpack -p --config webpack.config.root.js --watch",
"start:query": "SET NODE_ENV=development && webpack -p --config webpack.config.query.js --watch",

Related

nodemon, ts-node, not automatically recompiling

I am trying to create rest-api using, express+ts-node. I have done all setup based upon online tutorials, and when I run app using npm run dev it is working perfectly. But it is not restarting OnSave. This is my package.json script tag:
"scripts": {
"dev": "npm run nodemon src/index.ts",
"nodemon": "nodemon --watch 'src/**/*.ts' --ignore 'src/**/*.spec.ts' -r ts-node/register/transpile-only -r tsconfig-paths/register -r dotenv/config --exec ts-node --files src/index.ts",
"swagger": "tsoa spec"
},
Looks like nodemon not watching file changes. Please help, how to do restart on save.
try to install the ts-node-dev library then use this command in dev:

Can not run Nodemon in node project build with Typescript (In Windows)

Node project is built with Typescript and there are three script in package.json file but when I run it shows ...
If i run this project in ubuntu it works fine but not in windows
Image of output terminal
but after this nodemon is not start to run project.
Script in Package.json
"start": "tsc --watch & nodemon dist/index.js",
"lint": "tslint -c tslint.json 'src/**/*.ts' --fix",
"build": "tsc"
Help me to solve this, Thank you in advance :)
You seem to be missing an & character between tsc --watch and nodemon dist/index.js. A single & is not a valid and operator:
"start": "tsc --watch && nodemon dist/index.js",
Update It looks like the issue is on Windows. Commonly this issue is solved by using a library such as concurrently or cross-env to execute commands in a similar way on Windows. After you've installed concurrently:
"start": "concurrently \"tsc --watch\" \"nodemon dist/index.js\"",
Hopefully that helps!

Failed to write to file: ENOENT: no such file or directory

I am trying to build a folder with the name of build which will gonna contains number of map files and JavaScript files. But i'm getting an issue shown below.
Code :
"scripts": {
"prestart": "d2-manifest package.json manifest.webapp",
"start": "webpack-dev-server",
"test": "echo Everything probably works great\\! ## karma start test/config/karma.config.js --single-run true",
"build": "rm -rf build && set NODE_ENV=production webpack --progress && npm run manifest",
"postbuild": "cp -r src/i18n icon.png ./build/",
"validate": "npm ls --depth 0",
"manifest": "d2-manifest package.json build/manifest.webapp",
"deploy": "npm run build && mvn clean deploy",
"lint": "echo Looks good."
}
Error :
(I'm ignoring the fact that you seem to run this on a Windows machine)
The set command does not do what you think it does. To set an environment variable for a command, use
VARIABLE=value cmd
or
env VARIABLE=value cmd
This means changing
set NODE_ENV=production webpack --progress
into
env NODE_ENV=production webpack --progress
With set NODE_ENV=production webpack --progress you just set the positional parameters of the current shell instance to NODE_ENV=production, webpack and --progress.

Increase node memory using npm package.json script

If you want to increase the memory limit in node, the option to be passed will be:
node --max-old-space-size=4096 yourFile.js
But in my scenario I am using yarn, my package.json looks like this:
{
"name": "myapp",
"productName": "myapp",
"version": "1.0.0",
"main": "app/main.js",
...
"scripts": {
"package-win": "npm run build && build --win --x64",
"package-mac": "npm run build && build --mac",
...
},
...
I execute yarn package-win on a windows machine to invoke electron-builder for my electron app built with react.js. But I get always npm ERR! code ELIFECYCLE Due to out of memory. In my mac also got the FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory Error but still got the packages generated (how? I don't know) when invoking yarn package-mac.
I search a lot on how to use the --max-old-space-size=4096 option, but I haven't found anything that works.
I tried "package-win": "node --max-old-space-size=4096 npm run build && build --win --x64", But the path have problems locating npm. Even if I use which npm, still which is not recognized.
Thanks for helping.
Answering to myself: Using this options in package-win is wrong. As package-win executes the build task, then:
"build": "npm run build-main && npm run build-renderer",
...
"build-main": "cross-env NODE_ENV=production node --max_old_space_size=6144 --optimize_for_size --stack_size=6144 --trace-warnings -r babel-register ./node_modules/webpack/bin/webpack --config webpack.config.main.prod.js --progress --profile --colors",
"build-renderer": "cross-env NODE_ENV=production node --max_old_space_size=6144 --optimize_for_size --stack_size=6144 --trace-warnings -r babel-register ./node_modules/webpack/bin/webpack --config webpack.config.renderer.prod.js --progress --profile --colors",
That way it works!
You don't have to use option in package-win.
The way you should use-
"build-ts-prod": "node --max-old-space-size=1024
./node_modules/typescript/bin/tsc --skipLibCheck --diagnostics",

nodemon ''mocha' is not recognized as an internal or external command, operable program or batch file

Running a test for a nodejs project on windows 10
with the line in package.json as:
"test": "nodemon --exec 'mocha -R min'"
I get:
> nodemon --exec 'mocha -R min'
[nodemon] 1.11.0
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: *.*
[nodemon] starting `'mocha -R min'`
''mocha' is not recognized as an internal or external command,
operable program or batch file.
[nodemon] app crashed - waiting for file changes before starting...
rs
[nodemon] starting `'mocha -R min'`
''mocha' is not recognized as an internal or external command,
operable program or batch file.
[nodemon] app crashed - waiting for file changes before starting...
That worked fine with the line:
"test": "nodemon --exec \"mocha -R min\""
in package.json
install mocha globally then it will work
npm install -g mocha --save-dev
If you are using windows OS the do not use the single quotes
"test": "nodemon --exec 'mocha -R min'"
Use this
"test": "nodemon --exec mocha -R min"
Visit: www.mycodingx.com for more
"test": "mocha **/*.test.js",
"test-watch": "nodemon --exec \"npm test\""
For Run
npm run test-watch
Also, check your NODE_ENV=development if you are on Windows and are using git-bash. For some reason, it defaults to production.
$ echo $NODE_ENV
With the --production flag (or when the NODE_ENV environment variable is set to production), npm will not install modules listed in "devDependencies"
You can verify this by checking your node_modules/ folder and see if mocha was installed. If not:
$ npm install --only=dev
also:
$ NODE_ENV=development
$ npm i -D mocha
would do the trick.
I am no Windows kernel or any .. expert. In my case the test script kept erroring out with the message npm is not recognized as an Internal or External command.
a) When I had it as
"test": "mocha **/*.test.js",
"test-watch": "nodemon --exec 'npm test'"
It ran a few times and stopped and the error started occurring so when I switched to
"test": "mocha **/*.test.js",
"test-watch": "nodemon --exec \"npm test\""
Still I kept getting the same error of npm not recognized...
And no matter how many times I issued Ctrl c, the nodemon wouldn't stop.
I did take the steps of restarting my laptop, uninstalled and re-installed nodeJs, updated the PATH variable in Control Panel - User Accounts - Environment variables all amounting to no end in sight.
This leads me to believe that somewhere or somehow, either nodemon or mocha not sure, what is hanging, so even after I had modified to escape and use double quotes as in
"test": "mocha **/*.test.js",
"test-watch": "nodemon --exec \"npm test\""
I still kept getting the same error.
b) So then I changed the name of the key from test-watch to test-new
"test": "mocha **/*.test.js",
"test-new": "nodemon --exec \"npm test\""
and ran
npm run test-new
and every tests runs fine.
Go figure...
So I think I will stick to keeping unique test script names between different projects. I have no other explanation.... Anyone can shed light on this? Please do so...
for executing npm test command install mocha globally with -g
command: npm install mocha -g
I had the same issue and worked after installing mocha globally.
provided you have all dependency ready in your project
Inside the package.json, you need to add a new script right after the "test" script. We can create a custom script and named it as "test-watch" and the value of the "test-watch"is "nodemon --exec \"npm test\""(i.e "test-watch": "nodemon --exec \"npm test\"") After this step we can use npm run test-watch command in terminal.
An alternative approach is to add the mocha path to the environment variables then restart the bash
On your editor, navigate to the bin folder of mocha and add both paths to your system environments.
All script options that have been illustrated work with this approach
"scripts": {
"test": "nodemon --exec \"mocha -R min\""
}
or
"scripts": {
"test": "nodemon --exec 'mocha -R min'"
}
or
"scripts": {
"test": "nodemon --exec mocha -R min"
}
in the package.json file are correct dependencies definition
I hope this helps fix the issue.
Use "npm run test" and the command should be "nodemon --exec "mocha -R min"". For me, it worked when the previous command is used instead of the npm test & "nodemon --exec 'mocha -R min'"

Resources