Running yarn scripts in WebStorm with non-system node binary - node.js

I'm attempting to use WebStorm for a new project and use yarn instead of npm. However, after generating the project I can't get the scripts to run via yarn. My start script has the following run configuration in WebStorm.
package.json: ~/dev/starting_sandbox/package.json
Command: run
Scripts: start
Node Interpreter: ~/.nvm/versions/node/v7.8.0/bin/node
Npm package: ~/.nvm/versions/node/v7.8.0/lib/node_modules/yarn
When this runs I get an error:
/Users/byronsm/.nvm/versions/node/v7.8.0/bin/node /Users/byronsm/.nvm/versions/node/v7.8.0/lib/node_modules/yarn/bin/yarn.js run start
yarn run v0.21.3
$ react-scripts start
~/dev/starting_sandbox/node_modules/cross-spawn/index.js:34
throw new Error(
^
Error: In order to use spawnSync on node 0.10 or older, you must install spawn-sync:
npm install spawn-sync --save
at Function.spawnSync [as sync] (~/dev/starting_sandbox/node_modules/cross-spawn/index.js:34:19)
at Object.<anonymous> (~/dev/starting_sandbox/node_modules/react-scripts/bin/react-scripts.js:22:22)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:929:3
error Command failed with exit code 8.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
I was able to solve this problem in webpack when running the scripts via npm by using the --scripts-prepend-node-path option. However, this doesn't seem to exist for yarn.
This seems to be an issue with the instance of node that yarn runs when executing the scripts, instead of pulling from the same node binary used to execute yarn itself, it uses what it finds in $PATH, which isn't modified.
Is there a similar command you can use for yarn?

Related

after webpack i got error Cannot find module 'resolve-cwd'?

**I got error while webpack**
error is :
webpack
internal/modules/cjs/loader.js:638
throw err;
^
Error: Cannot find module 'resolve-cwd'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
at Function.Module._load (internal/modules/cjs/loader.js:562:25)
at Module.require (internal/modules/cjs/loader.js:692:17)
at require (internal/modules/cjs/helpers.js:25:18)
at Object.<anonymous> (/usr/share/nodejs/webpack/node_modules/import-local/index.js:3:20)
at Module._compile (internal/modules/cjs/loader.js:778:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
please help me to resolved this problem.
I tried this one
npm install resolve-cwd .
still i am getting same issues after type webpack.i also delete node_module folder and package_json_lock file and npm install .after this run webpack still got same above error .
node --version
v10.19.0
npm --version
7.10.0
I'm not entirely sure why this happened. But I can speculate that it is due to old webpack version.
I've faced this issue right now.
I had installed webpack using apt (on Ubuntu 20.04.2 (Focal Fossa)).
Reinstalling webpack using npm resolved the issue.
Steps I followed:
$ rm $(which webpack); # removes the currently installed webpack
# you can replace $(which webpack) with the webpack location
$ npm i -g webpack webpack-cli
Despite installing the missing module 'resolve-cwd' it kept failing with another missing module.
I had to delete the node_modules folder then re-running the npm install command to install dependencies. This worked for me
I had the same issue with Resolve-CwD. But in my case it was caused by yarn not installing webpack properly.
You have an older version of node so try updating it and see if the above steps are working.
If it's not working then i'd say you try an older version of Ruby until the current issue with har-validator is sorted
In my case the error was caused because yarn was using har-validatior which is deprecated and just couldn't install webpack completely
In my case, showed me this too
So I just installed the cwd module with: npm install resolve-cwd.
And it fixed my problem.
If you are using ubuntu just add sudo before the 'webpack' command. In my case, this omission caused an error with 'resolve-cwd'

how to install sqlite3 in electron?

So here is what i did, i installed electron and sqlite3 inside my project directory
npm install electron --save-dev
npm install sqlite3
but when i try to run this using npm start it gives me error
var sqlite3 = require('sqlite3').verbose();
this line is inside my main.js where i initialize electron things etc. and it works fine without this line.
here's the error i get.
Uncaught Exception:
Error: Cannot find module '/home/touseef/Desktop/Projects/pos/node_modules/sqlite3/lib/binding/electron-v6.0-linux-x64/node_sqlite3.node'
Require stack:
- /home/touseef/Desktop/Projects/pos/node_modules/sqlite3/lib/sqlite3.js
- /home/touseef/Desktop/Projects/pos/main.js
- /home/touseef/Desktop/Projects/pos/node_modules/electron/dist/resources/default_app.asar/main.js
-
at Module._resolveFilename (internal/modules/cjs/loader.js:627:15)
at Function.Module._resolveFilename (/home/touseef/Desktop/Projects/pos/node_modules/electron/dist/resources/electron.asar/common/reset-search-paths.js:41:16)
at Function.Module._load (internal/modules/cjs/loader.js:531:27)
at Module.require (internal/modules/cjs/loader.js:685:19)
at require (internal/modules/cjs/helpers.js:16:16)
at Object.<anonymous> (/home/touseef/Desktop/Projects/pos/node_modules/sqlite3/lib/sqlite3.js:4:15)
at Module._compile (internal/modules/cjs/loader.js:786:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:798:10)
at Module.load (internal/modules/cjs/loader.js:645:32)
at Function.Module._load (internal/modules/cjs/loader.js:560:12)
My node version is 10.16.3 and i'm running Ubuntu.
Just had this issue too. I had to rebuild sqlite3.
Installed electron-rebuild, and added "scripts": { "rebuild": "electron-rebuild -f -w sqlite3" },
to my package.json. Then executed npm run rebuild, and let it rebuild. Got rid of this error for me.

Npm not working after yarn install (cannot find number-is-nan)

I installed yarn via brew to my macOS 10.13 and yarn works just fine. The problem occurs when i try to use npm. I get the following error on every command i try to run:
gregor-mbp:~ gregor$ npm -v
module.js:471
throw err;
^
Error: Cannot find module 'number-is-nan'
at Function.Module._resolveFilename (module.js:469:15)
at Function.Module._load (module.js:417:25)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npmlog/node_modules/gauge/node_modules/string-width/node_modules/code-point-at/index.js:2:19)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
I tried to install this number-is-nan module as global via yarn but no success.
Now i have to install all packages and run scripts over yarn which is not bad but my projects have scripts which run other scripts via npm:
package.json example:
...
"scripts": {
"start": "start-command",
"build": "build-command",
"development": "NODE_ENV=dev npm run build && npm run start",
"production": "NODE_ENV=prod npm run build && npm run start"
},
...
And when i run yarn development i get the same error as above. While i'm only one in development team that has yarn installed i cannot change the configurations to yarn because others use npm.
So i there any solution to this, so yarn and npm could co-exist on same system without errors? Or should i just delete yarn?
Try to use yarn to reinstall npm:
yarn global add npm

create-react-app in WebStorm

I am attempting to use the npm package "create-react-app" to get started on a react project using WebStorm.
I have run npm install -g create-react-app to install the package globally, and can use the package perfectly fine with from the command line (i.e. create-react-app <proj name>).
However when creating a project in WebStorm and using the path to the global "create-react-app" package (found using npm list -g), I encounter this error:
/usr/bin/node /usr/local/lib/node_modules/create-react-app/index.js .
/usr/local/lib/node_modules/create-react-app/createReactApp.js:589
.filter(file => !validFiles.includes(file));
^
TypeError: validFiles.includes is not a function
at /usr/local/lib/node_modules/create-react-
app/createReactApp.js:589:33
at Array.filter (native)
at isSafeToCreateProjectIn (/usr/local/lib/node_modules/create-
react-app/createReactApp.js:589:6)
at createApp (/usr/local/lib/node_modules/create-react-
app/createReactApp.js:147:8)
at Object.<anonymous> (/usr/local/lib/node_modules/create-react-
app/createReactApp.js:134:1)
at Module._compile (module.js:410:26)
at Object.Module._extensions..js (module.js:417:10)
at Module.load (module.js:344:32)
at Function.Module._load (module.js:301:12)
at Module.require (module.js:354:17)
Done
Have I gone wrong at some point?
It turns out I had node version 4, and create-react-app requires version >= 6 - although this warning was not displayed via the WebStorm "Run" panel.
Thus I fixed this issue by updating to node v6.11.3, using nvm.

Error - Cannot find module 'broccoli'

I'm getting this error and cannot find any way to fix it. It occurs upon trying to execute broccoli build.
Error: Cannot find module 'broccoli' from '/Users/devel/Projects/broccoliTest'
at Function.module.exports [as sync] (/usr/local/lib/node_modules/broccoli-cli/node_modules/resolve/lib/sync.js:32:11)
at Object.<anonymous> (/usr/local/lib/node_modules/broccoli-cli/bin/broccoli:7:28)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:906:3
I've just installed sudo npm install -g broccoli and sudo npm install -g broccoli-cli. The broccoli executable file is fine, obv:
>which broccoli
/usr/local/bin/broccoli
so it seems that the broccoli module is not correctly installed, although no error occured in the installation process.
ls /usr/local/lib/node_modules/broccoli
CHANGELOG.md LICENSE README.md docs lib node_modules package.json templates
Any ideas?
Globally installed packages aren't made available to require(), by design:
Install it locally if you're going to require() it.
Install it globally if you're going to run it on the command line.
If you need both, then install it in both places, or use npm link.
You'll have to also install it locally, relative to your scripts:
cd /Users/devel/Projects/broccoliTest
npm install broccoli
You can execute you command using a relative path like this:
./node_modules/.bin/broccoli build
To avoid that you can use broccoli-cli to take care of figuring out the path for you.
yarn add -D broccoli-cli
npm install --save-dev broccoli-cli
Or you can just install it globally.

Resources