I keep getting the below error whenever the terminal restarts.
which node
node not found
yarn global bin
env: node: No such file or directory
After running the below command, it starts working and displays the installation folder as below:
nvm use 16 && yarn global bin
/Users/<username>/.yarn/bin
How can I move this to /usr/local/bin?
Related
I use this command line:
npx react-native init AwesomeProject1
And find this error:
✖ Downloading template
error Error: Command failed: yarn init -y
Usage: yarn [options]
yarn: error: no such option: -y
Update:
npm uninstall --location=global yarn
this line solved my problem. Can anyone explain why this works?
Based on yarn global documentation
yarn global is a prefix used for a number of commands like add, bin, list and remove. They behave identically to their normal versions except that they use a global directory to store packages. The global command makes executables available to use on your operating system.
So you could add the install location to your system environment variable like this to use the installed packages:
export PATH="$(yarn global bin):$PATH"
Or you can do that with yarn commands like this:
First find installation location
yarn global bin
Then configure the base location with the following command
yarn config set prefix <filepath>
I am using Lerna (https://github.com/lerna/lerna) for managing my monorepo with the following structure:
-yarn.lock
-package.json
-node_modules
-packages
--app
---app1
----package.json
----src
----dist
(The above structure is the minimal example I could give, actual project has many more sub repos but this is the only one that's built on Jenkins.)
On my local machine with Yarn and NPM version as follows:
yarn: 1.22.10
node: v12.14.1
I run the following commands to build my APP1 from my root directory
yarn
cd ./packages/app/app1
yarn build
which generates dist folder in packages/app/app1.
But when I run the same set of commands on Jenkins I get the following error:
error No lockfile in this directory. Run yarn install to generate one.
error Command failed with exit code 1.
Since I'm using lerna, my lockfile is in root directory. Why am I getting this error? Why not on local machine?
Node and Yarn versions on Jenkins:
yarn: 1.9.10
node: v12.16.1
follow the tips run "yarn install",then run "yarn upgrade"
Created a default create-react-app project. And tried to run it yarn start. Tried to run it in cmd, powershell.
And getting an error:
my-app/node_modules/.bin/react-scripts: node: not found
This is the problematic line in the script:
node "$basedir/../react-scripts/bin/react-scripts.js" "$#" <-- node not found
I checked my PATH vars and set a high priority for C:\Program Files\nodejs
Reinstalled node.js and installed a different version 12.14
UPDATE:
If I run it in bash it works properly. But still, though need to solve it on other terminals
The problem was I had installed WSL and somehow it was running in that environment and there wasn't Node installed there. So I removed WSL and now it runs okay.
I ran the following command for my node app:
$ npm install browser-sync --save-dev
Installation was successful, browser-sync appears in my package.json file as well as my node_modules directory.
However, when I run $ browser-sync --version to check that it's working, I get the following error:
bash: browser-sync: command not found
Why isn't this working?
Note: this question is similar, but I don't want to have to install it globally as in this question.
Any help would be greatly appreciated!
This is because you're trying to use a module locally which is normally installed globally. Modules installed globally end up on your PATH environment variable, which is why you can run them from the terminal as you're trying to do:
$ browser-sync --version
If you want to use the browser-sync module from a local install you will have to prepend the full path to the browser-sync binary from within your .bin directory since all locally installed modules are placed within your current working directory node_modules directory. i.e. Node modules go in ./node_modules, executables go in ./node_modules/.bin/. So in order to run the browser-sync binary from a local install do the following:
./node_modules/.bin/browser-sync --version
Hopefully that helps!
If you installed browser-sync using npm --save or npm --save-dev you can run it by writing a script in your package.json. Here's an example of a script I added:
{
...
"scripts": {
"dev-server": "browser-sync start --server 'public' --files 'public'"
},
...
}
You can run the scripts from you project's root directory like so
npm run dev-server
This will run whatever command is set to dev-server in your script. In this case it will run browser-sync for the app/site in a folder called /public and watch for any file changes in the /public folder. I know this question is a bit old but it was unanswered and hopefully I can save someone time in the future.
The other answers still work, but a newer approach has emerged since npm added the npx command: npx <package-name>.
This command allows you to run an arbitrary command from an npm
package (either one installed locally, or fetched remotely), in a
similar context as running it via npm run.
Source: https://docs.npmjs.com/cli/v8/commands/npx
In this case, you would run npx browser-sync.
As part of the setup for building my environment for a job in Jenkins, I have checked the
Provide Node & npm bin/ folder to PATH
At the moment it defaults to Installation NodeJS
When running a job it gets to this point
$ /Users/jenkins/.jenkins/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/NodeJS/bin/npm install -g grunt-cli
but returns
env: node: No such file or directory
When manually going to the npm folder I cannot cd into it but a ls -la outputs
npm -> ../lib/node_modules/npm/bin/npm-cli.js
What is happening here, and why am I getting the error?