I am getting some issues running a script from Yarn. I need to run the script from a project subfolder and getting access to the folder that contains the package.json
This is the folder structure:
package.json
src
module1
module2
If I run yarn myscript from the module2 folder I will get access to env variable INIT_CWD (the location where I run the command) but there is no information on the location of package.json.
The script in yarn is something like:
node --inspect $(which serverless) offline \
--dbHost localhost --noAuth \
--location $HERE_IS_WHERE_THE_INFO_IS NEEDED"
It seems that it is possible to use the $PWD variable as it is filled with the package.json location, even if you run yarn "script" from a subfolder
Related
By default node_modules folder is under the root directory of my Laravel project and it's working fine. I can compile the scripts with npm run dev and there is no error.
However according to the project folder structure, I move node_modules folder into a child folder called backend.
Here, I also moved the files like webpack.mix.js, package.json into backend folder and run npm install again inside it. But I keep my resources and public folders as original and link them with relative path via backend folder.
The folder structure looks like this
Now, if I run npm run dev inside backend folder, it complains many errors like can't resolve '#babel/runtime/regenerator'.
But if I make a symbolic node_modules inside root folder which is linked to backend/node_modules, it works fine and I can compile the scripts without error.
My question is - How can I compile the scripts from child folder without making a symbolic like this?
Probably it doesn't know where node_modules folder is located.
As laravel-mix is based on webpack. I add the modules path inside webpack config as below to make all import knows where the node_modules folder is located.
mix.webpackConfig({
resolve: {
modules : [
path.resolve("./node_modules")
]
}
});
There is no more can't resolve error.
How can I run a script from the node_modules/.bin directory with Yarn 2 ?
Example
Suppose I need to run an "eslint" script located in that directory
node_modules
├── .bin
│ ├── eslint
With NPM, I can just run npx eslint to run the excutable. How can I achieve this with Yarn 2 ?
It is same as what it used to be in classic Yarn, run this:
yarn eslint
Refer: https://yarnpkg.com/cli/run#details
This command will run a tool. The exact tool that will be executed will depend on the current state of your workspace:
If the scripts field from your local package.json contains a matching script name, its definition will get executed.
Otherwise, if one of the local workspace's dependencies exposes a binary with a matching name, this binary will get executed.
Otherwise, if the specified name contains a colon character and if one of the workspaces in the project contains exactly one script with a matching name, then this script will get executed.
If you want to ignore any user defined scripts and only check for binaries, you can pass -B option.
There is also yarn exec:
yarn exec eslint
I have project files in folder:
./project/java_files/
if i go to java_files && run mvn package - all works correctly.
but how i can start same from ./project folder?
I mean without cd ./java_files of course...
you can run maven command as below, passing path to pom.xml
mvn package -f /path/to/pom.xml
In my package.json file I have a script that I'm running
node src/validateRun.js
I'm trying to run that script in the Xcode build phase. the script is located in the src/ so the build is successful but the script is never running.
Here is my build phase config:
shell: /bin/sh
SRC_DIR="../src/"
node "$SRC_DIR/validateRun.js"
is there any reason why the script is not running ?
Apparently instead of execute node file.js you should type it like this:
/usr/local/bin/node your_file.js
Here is my problem, I constructed a dockerfile launching yarn install from a folder where a package.json and yarn.lock are present (they have been taken from the project I have to setup yarn dependencies for, this project is inside a deconnected server).
Then, I run bash into container image and uploaded the created folder node_modules, and put it into the deconnected server, where project is present, at root folder project.
But then, when I launched yarn start from root folder, it says that it cannot find rescripts despite of the fact that folder #rescripts is present into node_modules.
I tried NODE_PATH=./node_modules yarn start without any success.
Thanks a lot for your help.
Regards
I think i get what i want with :
https://yarnpkg.com/blog/2016/11/24/offline-mirror/
I create a cache folder with all tar.gz dependencies downloaded.
But if i remove node_modules and yarn.lock, and run yarn install --offline --cache-folder npm-packages-offline-cache/, I got error saying it could not find proper dependance in cache folder. It's like it cannot recognize any tar.gz inside. Any help will be welcome.
Regars