Electron forge start is broken by Gulp - node.js

please help because this thing is driving me crazy. In short when gulp reference is added to electron-forge project app launch fails.
Node: v8.11.3
electron-forge: v5.2.2
Package.js snippet:
"dependencies": {
"electron-squirrel-startup": "^1.0.0",
"electron-compile": "6.4.3"
},
"devDependencies": {
"electron": "2.0.4",
"electron-forge": "^5.2.2",
"electron-prebuilt-compile": "2.0.4",
"gulp": "^3.9.1"
}
Steps to reproduce:
electron-forge init gulptest
npm install electron-prebuilt-compile -D
npm install gulp -D
Add electron-prebuilt-compile to devDependencies in package.json
npm run start
App will start normally, but if only one line is added to the index.js start command fails.
const gulp = require('gulp');
Once started console will output error with description:
c:\projects\electron\vendor\node\src\async-wrap.cc:357 Assertion 'env->async_hooks_init_function().IsEmpty()' failed.

This is electron issue. There is a bug opened for this and it will be fixed in one of the future releases.

Related

Adding SASS to React Project Stalls Yarn Start

I'm mid-way though a React project and am now adding styles and implementing SASS, and the other day while I added the packages and some styles, everything was running great. Today I go to boot it up with Yarn Start and and I'm getting:
npm WARN lifecycle The node binary used for scripts is /var/folders/hd/zrndmrss6z3cbm68fxxyt4wm0000gn/T/yarn--1553472972241-0.9303472274627695/node but npm is using /Users/kevinhyde/.nvm/versions/node/v11.10.0/bin/node itself. Use the `--scripts-prepend-node-path` option to include the path for the node binary npm was executed with.
> test-again#0.1.0 css-watch /Users/kevinhyde/Desktop/CAREER/UW Code Camp/Post_Grad_Apps/test-again
> npm run css-build -- --watch
npm WARN lifecycle The node binary used for scripts is /var/folders/hd/zrndmrss6z3cbm68fxxyt4wm0000gn/T/yarn--1553472972241-0.9303472274627695/node but npm is using /Users/kevinhyde/.nvm/versions/node/v11.10.0/bin/node itself. Use the `--scripts-prepend-node-path` option to include the path for the node binary npm was executed with.
> test-again#0.1.0 css-build /Users/kevinhyde/Desktop/CAREER/UW Code Camp/Post_Grad_Apps/test-again
> node-sass --omit-source-map-url sass/mystyles.scss css/mystyles.css "--watch"
I have just following packages:
"dependencies": {
"axios": "^0.18.0",
"bulma": "^0.7.4",
"bulma-extensions": "^6.2.0",
"dotenv": "^6.2.0",
"node-sass": "^4.11.0",
"react": "^16.8.3",
"react-bulma-components": "^2.3.0",
"react-dom": "^16.8.3",
"react-scripts": "2.1.5"
},
So far I have tried node re-installs on the related packages and straight up npm i, as well as npm audit to try to fix, but when I jumped back to the previous branch before adding node-sass, all's well. Any ideas?

Nodemon installed but not working in Node.js

I am using Node.js with express.js and I also installed Nodemon ( exist in node_modules folder) but it's not working.
Here is my package.json code. How can I solve this ?
// package.json
{
"name": "node-api",
"main": "server.js",
"dependencies": {
"express": "~4.0.0",
"mongoose": "~3.6.13",
"body-parser": "~1.0.1"
}
}
add nodemon as a dev dependency
npm i -D nodemon
Or install globally
npm i -g nodemon
But , in second method it will not show in package.json file
There is no need to use --save or -S as it is not used in your main code
EDIT: Jan 6, 2019
Use nodemon in script tag in package.json file. Like
"scripts" : {
...
"start" : "nodemon index.js"
}
Then use npm start in terminal
hit npm install --save nodemon -g in terminal or
install in your project via npm install --save nodemon
and it should display your package.json like
{
"name": "node-api",
"main": "server.js",
"dependencies": {
"express": "~4.0.0",
"mongoose": "~3.6.13",
"body-parser": "~1.0.1",
"nodemon": "^1.18.6"
}
}
and run nodemon server.js
check if nodemon is installed nodemon -v
This issue is very much common. It showed 'found 0 vulnerabilities' while installing but never showed in dev dependencies.
I tried restarting my text editor and run the command again
npm i --save-dev nodemon
it started working.
In my case i able to solve this issue by update the node.
now for update you have to download node from https://nodejs.org/en/
it worked for me
hope will work for you as well

npm not installing dependency of dev dependency when it's also listed as app dependency

This one has me stumped. Very easily reproducible.
package.json
{
"dependencies": {},
"devDependencies": {
"gulp": "^3.9.1",
"gulp-less": "^4.0.1"
}
}
Put that in a folder and run npm install --only=dev. I'm using node v8.9.4 and npm v6.4.1.
Everything will install fine. Open the node_modules directory and verify that the less module is there, because it's a dependency of gulp-less. You can use this gulpfile.js to test:
var gulp = require('gulp');
var less = require('gulp-less');
gulp.task('default')
Okay, now add "less": "^3.8.1" to "dependencies" so your package.json looks like this:
{
"dependencies": {
"less": "^3.8.1"
},
"devDependencies": {
"gulp": "^3.9.1",
"gulp-less": "^4.0.1"
}
}
Remove the node_modules folder and package lock file and re-run npm install --only=dev.
You will see that you cannot run the gulp file now, and if you open and look for the less package in node_modules it will not have been installed.
This is repeatable behavior for me. Any time I add less to the app dependencies, it is never installed when I do install --only=dev.
Am I missing something about how this is supposed to work or did I find a bug?

Webpack not working in my node.js project. fsevents

I'm currently trying to implement this tutorial:
https://www.typescriptlang.org/docs/handbook/react-&-webpack.html
I'm supposed to install react and react-dom and also webpack + typescript + awesome-typescript-loader + source-map-loader, and that's what I did. I also installed webpack-cli accordingly to instructions that I got from the command line.
I installed all of them locally (the react and react-dom as PROD and the rest as DEV dependencies).Currently I don't have any packages installed globally.
After this, that's my package.json file:
{
"name": "reactandwebpack-tutorial",
"version": "1.0.0",
"description": "",
"main": "webpack.config.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"devDependencies": {
"awesome-typescript-loader": "^5.2.0",
"source-map-loader": "^0.2.3",
"typescript": "^2.7.2",
"webpack": "^4.16.4",
"webpack-cli": "^3.1.0"
},
"dependencies": {
"#types/react": "^16.4.7",
"#types/react-dom": "^16.0.6",
"react": "^16.4.2",
"react-dom": "^16.4.2"
}
}
At this point, when I run npm ls I get a bunch of errors, because of some optional dependency of webpack that apparently is missing (all the errors in the tree are inside webpack and below fsevents as following):
webpack#4.16.4
(...)watchpack#1.6.0
(...)chokidar#2.0.4
(...)fsevents#1.2.4 -> UNMET OPTIONAL DEPENDENCY
And everything below fsevents is also marked with UNMET DEPENDENCY
And when I run webpack command, I get a "webpack not recognized error".
Anyone can help? I've been trying to wrap my head around this for a while.
PS:
Npm -v 5.6.0
Node -v 8.11.3 //(that's what I get from the terminal,
//VSCode "About" tells me something different, I don't know why).
Using Visual Code
Version 1.24.0
Date 2018-06-06T17:35:40.560Z
Shell 1.7.12
Renderer 58.0.3029.110
Node 7.9.0
Architecture x64
The reason is because it was not linked to your env. When you install something globally, you have access to it everywhere, hence it works just by doing webpack. Since you installed everything locally, the binaries are located inside node_modules/.bin.
You have two options when you install something locallly.
Use npm scripts (npm run build, watch... whatever).
./node_modules/.bin/moduleName --flags
It is easier to create a npm script and add all the commands there.
SOLVED
Not sure the reason but it had something to do with the ./bin folder with the webpack-cli "ambient variable" not being available (I don't know it that would be the most accurate description).
When I try to run webpack, I get "not recognized error".
But when I run nodemodules\.bin\webpack-cli it works normally.
Everything is installed locally.
I can also run it with options, like nodemodules\.bin\webpack-cli --help
If you run "webpack", The CLI will find global webpack with is installed by (npm install webpack -g). To use webpack from local project. you should it to npm script.
package.json
{
"script": {
"start": "webpack"
}
}
By doing this, you can run npm start to run webpack.

TypeError: Invalid Version: undefined using Gulp in Visual Studio

I'm new to all of this Node.js, npm, Bower and Gulp stuff so I'm trying to start get familiar with it. I started by installing Node.js which seemed to go smoothly. I then installed gulp both globally and locally according to what I've found online:
> npm install --global gulp
> npm install --save-dev gulp
The second one was of course done in the directory of my project and it did indeed update my package.json file.
So I now have a package.json file that looks like this:
{
"name": "typescripttestapp",
"version": "1.0.0",
"description": "",
"main": "index.html",
"dependencies": {
},
"devDependencies": {
"del": "^1.2.0",
"gulp": "^3.9.0",
"gulp-concat": "^2.6.0",
"gulp-copy": "0.0.2",
"gulp-typescript": "^2.7.8"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}
I've also installed Task Runner Explorer in Visual Studio. I have the following gulpfile.js:
var gulp = require('gulp');
gulp.task("default",function(){});
However, any time I try to refresh the Task Runner Explorer, I get the following error in the Output Window:
Failed to load
"F:\Business\Development\TestSandBoxes\TypeScriptTestApp\TypeScriptTestApp\gulpfile.js"...
C:\Users\rodd_harris\AppData\Roaming\npm\node_modules\gulp\node_modules\semver\semver.js:281
throw new TypeError('Invalid Version: ' + version);
^ TypeError: Invalid Version: undefined
at new SemVer (C:\Users\rodd_harris\AppData\Roaming\npm\node_modules\gulp\node_modules\semver\semver.js:281:11)
at SemVer.compare (C:\Users\rodd_harris\AppData\Roaming\npm\node_modules\gulp\node_modules\semver\semver.js:348:13)
at compare (C:\Users\rodd_harris\AppData\Roaming\npm\node_modules\gulp\node_modules\semver\semver.js:571:31)
at Function.gt (C:\Users\rodd_harris\AppData\Roaming\npm\node_modules\gulp\node_modules\semver\semver.js:600:10)
at Liftoff.handleArguments (C:\Users\rodd_harris\AppData\Roaming\npm\node_modules\gulp\bin\gulp.js:99:14)
at Liftoff. (C:\Users\rodd_harris\AppData\Roaming\npm\node_modules\gulp\node_modules\liftoff\index.js:192:16)
at module.exports (C:\Users\rodd_harris\AppData\Roaming\npm\node_modules\gulp\node_modules\liftoff\node_modules\flagged-respawn\index.js:17:3)
at Liftoff. (C:\Users\rodd_harris\AppData\Roaming\npm\node_modules\gulp\node_modules\liftoff\index.js:185:9)
at C:\Users\rodd_harris\AppData\Roaming\npm\node_modules\gulp\node_modules\liftoff\index.js:159:9
at C:\Users\rodd_harris\AppData\Roaming\npm\node_modules\gulp\node_modules\v8flags\index.js:91:14
What am I doing wrong?
Edit
By some experimenting, I found that gulp will run if I do gulp -v first. If I open a command prompt and go to my project directory and just run gulp I get the same error as I do from Task Runner. However, if, as I said, I do the gulp -v first, then run gulp it works.
It would still be nice to know if I've got something configured wrong because at present, I'm still unable to set this up with Task Runner Explorer.
I found a solution to this issue, make sure you have run npm init in the base directory of your gulp file and then install gulp locally npm install gulp --save-dev. This seems to resolve it for me when running gulp in Visual Studio Code.

Resources