'What is the difference between the command that yarn run [dev] executes and its vanilla node implementation? [closed]

This is my package.json file. As you can see it has a dev command that I can execute with yarn dev Package.json

I figured that if I copy the command that yarn dev would run which is node .electron-nuxt/dev.js --inspect I would be able to run the command outside of yarn (to attach the script to my debugger with node). But when I copied that exact command, it produced no errors and did nothing. Why does yarn dev work but not node .electron-nuxt/dev.js --inspect if they point to the same piece of code?



Solution 1:[1]

This happens because of how npm/yarn locate executable files. It's called mode of operation and it's basically how these package managers resolve and execute modules.

While both behave somehow differently, the underlying operation is still similar. There are two modes local and global. the package manager tries to resolve the module in local mode first; that's from the directory where you run the script. If it didn't find it then it tries to resolve it from the global scope.

So to answer your question, yarn execute the file from the global scope.

  • Resources

How node resolves modules Node.js docs

The node_modules problem Yarn docs

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Youssef AbouEgla