I initiated an Nx workspace using npx:
npx create-nx-workspace
I get this after nx finished bootstrapping my workspace:
This means that you might have to use "yarn nx" or "npx nx" to execute command
s in the workspace.
Run "yarn global add nx" or "npm install -g nx" to be able to execute command
directly.
I want execute command directly and want to use yarn so:
yarn global add nx
and get success message:
yarn global v1.22.10
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
[4/4] Building fresh packages...
success Installed "nx#12.5.8" with binaries:
- nx
Done in 9.40s.
I cd into my workspace, and try to serve my 'todos' app using the nx cli that I installed previously:
cd myorg
nx serve todos
but I get this error:
bash: nx: command not found
I restarted my terminal and tried to serve again but got the same error. serve works if I do yarn nx serve todos, but, I would love to learn why and how I can make the direct command work with Yarn.
Related
I see with yarn berry I get the plug'n'play feature instead of node_modules/
I couldn't find anything to suggest it supports running from installed packages.
For example with npm a workflow might be to run the installed version of webpack:
$ npm install --save-dev webpack
$ node node_modules/webpack/bin/webpack ...
A globally installed webpack might not be the same version. Worse yet, during Docker deployment, I get what's installed locally, the only node and npm are available globally. I thought I can do a preinstall script that does npm install -g yarn; yarn set version berry but then I'm not sure how to do webpack, jest, babel, etc, and the thought that I should have to install them all globally during the same preinstall hackaround seems like several steps backwards.
Is there some way to run from locally-installed packages that I'm missing?
I saw this possibly related question - Yarn Berry - Run a Node Script Directly
But the answer there seems a bit off the point - I'm not running any js, I'm trying to type in a package.json script, i.e. something that can run from the shell.
Why not just use yarn run <bin> (or simply yarn <bin>)? If you are in a repository set to use yarn berry, that will run any package bin file.
yarn node <file> will run any .js file with Plug n' Play set up. No need to install those dependencies globally, except for maybe yarn classic.
I was trying to do yarn some-bin and kept getting:
Couldn't find a script named "some-bin".
I eventually figured out it was because the package that provides some-bin is installed inside a workspace and not at the root of my project. So instead I had to run:
yarn workspace my-workspace some-bin
And that worked.
Installed Adonis with yarn on Ubuntu 18 (running on WSL2 VM):
pomatti#NT-03024:~/Projects/myApp$ yarn global add #adonisjs/cli
yarn global v1.19.1
[1/4] Resolving packages...
[2/4] Fetching packages...
info fsevents#1.2.9: The platform "linux" is incompatible with this module.
info "fsevents#1.2.9" is an optional dependency and failed compatibility check. Excluding it from installation.
[3/4] Linking dependencies...
[4/4] Building fresh packages...
success Installed "#adonisjs/cli#4.0.12" with binaries:
- adonis
Done in 3.29s.
However when I try to run it, the command is not found:
pomatti#NT-03024:~/Projects/myApp$ adonis
adonis: command not found
What is odd is that my package.json commands are working properly and my app is started, but I am not able to call adonis directly in the command line (the global installation).
For example, yarn migration && adonis serve --dev --debug works.
"scripts": {
"serve": "adonis serve",
"migration": "adonis migration:run",
"start": "yarn migration && yarn serve",
"dev": "yarn migration && adonis serve --dev --debug",
"lint": "yarn eslint"
},
Try to install with NPM. Command:
> npm i -g #adonisjs/cli
Official documentation
For CLI tools installed with yarn global to work, you need to have the global yarn bin directory in your PATH. By default the yarn bin dir should be ~/.yarn/bin. To double check if that's right on your system and the adonis executable exists (assuming you've already run yarn global add #adonisjs/cli):
ls ~/.yarn/bin/adonis
(Mine is there).
To add that to my PATH:
cat > ~/.bashrc.d/yarn <<EOF
PATH="$HOME/.yarn/bin:\$PATH"
EOF
chmod +x ~/.bashrc.d/yarn
. ~/.bashrc.d/yarn
Then double check PATH: echo $PATH. Here's mine (after the above - your may not have all of these paths, but so long as it has /home/user/.yarn/bin - where user is your username):
/home/user/.yarn/bin:/home/user/bin:/home/user/.local/bin:/usr/lib/git-core:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
or neither.
I installed both grunt-cli and grunt globally as such
inst_grunt(){
# installs the grung-cli to
# /usr/local/lib/node_modules/grunt-cli
sudo npm install -g grunt-cli
# installs grunt based upon the package.json file to
# /usr/local/lib/node_modules/Grunt
sudo npm install -g
}
I thought I could simply run
grunt --gruntfile /Users/a/root/config/Gruntfile.js watch
as stated here:
How do I run grunt from a different folder than my root project
but alas I get this error:
as-MacBook-Air:config a$ grunt --gruntfile
/Users/a/root/config/Gruntfile.js grunt-cli: The grunt command line
interface. (v0.1.13)
Fatal error: Unable to find local grunt.
If you're seeing this message, either a Gruntfile wasn't found or
grunt hasn't been installed locally to your project. For more
information about installing and configuring grunt, please see the
Getting Started guide:
http://gruntjs.com/getting-started
The grunt file is there so I'm assuming it is looking for a local grunt installation.
You do have to install it locally in order to call functions on it within the gruntfile.
This way your project can specify what version of Grunt should be used (edit) in your package.json file.
I am using TeamCity as my CI server(mac).I am trying to build a web project. When I use grunt serve or grunt buildproduction after changing directory to the cloned folder,it's working perfectly fine.But when I do this via TeamCity server it is giving an error You need to have Ruby and Compass installed and in your system PATH for this task to work and gets aborted due to warnings. Ruby and Compass is already installed in the server.Please help me on this.
rm -rf $(pwd)/node_modules/*
rm -rf $(pwd)/bower_components/*
npm cache clear
npm install
npm install bower
npm install grunt-ftp-push --save-dev
bower install
grunt buildproduction
This is the Command Line buildstep which I used in Teamcity..
I would say you probably use a different user or the shell environment is different (interactive vs non-interactive) when you run these commands manually and when it runs through TC it can't find those packages in the environment/PATH
I have to switched on the second computer which is running on Windows XP.
I clonned my project from repository, which have structure containtng bower.jcon, Gruntfile.js and other following files and is running without problems on second computer with MacOS X.
After that I launched NodeJS command promtp, moved into the directory where application was clonned and i launched commmand.
C:\workspace\myproject>grunt serve
And I got following error message:
Loading "Gruntfile.js" tasks...ERROR
>> Error: Cannot find module 'load-grunt-tasks'
Warning: Task "serve" not found. Use --force to continue.
Whhat I'm doing wrong and how can i solve this issue please?
Many thanks for any help.
EDIT:
I solved it using the following commands:
npm update npm -g
npm install
bower install
grunt serve