Why the Node.js does not run sucrase-a locally installed package?

No Node.js, I installed on cmd the yarn (I can't use the yarn and I'm using the npm), but the same doesn't work. I chose to use npm and now when trying to use sucrase library (install: npm install --save-dev sucrase) and nodemon, it does not run.

Appears this:

...
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}
[nodemon] app crashed - waiting for file changes before starting...

Below the Package.json

    {
  "name": "teste",
  "version": "1.0.0",
  "description": "cursonode",
  "main": "app.js",
  "scripts": {
    "test": "echo \\\"Error> no test specified\\\" && exit 1"
  },
  "author": "Cesar Vitor",
  "license": "ISC",
  "dependencies": {
    "express": "^4.17.1",
    "mysql": "^2.17.1"
  }
}
Author: Luiz Felipe, 2019-12-13

3 answers

You can use the commands npm run or yarn run to run any binary that has been installed locally. This means that you can run "CLIS" provided by packages without the prefix ./node_modules/.bin.

For example, if you have installed locally the package sucrase, and run it using one of the two commands above, Yarn or NPM will manage the command for you.

So once you have installed your package:

yarn add sucrase --dev # Para Yarn
npm install sucrase --save-dev # Para NPM

You can configure the following in the field scripts of your package.json:

// [...]
"scripts": {
  "build": "yarn run sucrase ./your-file.tsx" // Ou `npm run sucrase ./your-file.tsx`
}
// [...]

Remember that Yarn and NPM interpret what you put after yarn run (or npm run) as a normal command. You will only be able to use, however, the locally installed commands in your package. To see all available binaries, just look at the files inside the node_modules/.bin folder.

 1
Author: Luiz Felipe, 2019-12-14 02:12:16

After doing what you recommended a new error appeared:

Npm run sucrase ./ src / app.js

Npm ERR! missing script: sucrase

Npm ERR! A complete log of this run can be found in:

Npm ERR! C:\Users\Edilson\AppData\Roaming\npm-cache_logs\2019-12-14T16_43_03_487Z-debug.log

Npm ERR! ELIFECYCLE Code

Npm ERR! errno 1 npm ERR! [email protected] build: npm run sucrase ./src/app.js

Npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the [email protected] build script.

Npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

Npm ERR! A complete log of this run can be found in: npm ERR! C:\Users\Edilson\AppData\Roaming\npm-cache_logs\2019-12-14T16_43_03_527Z-debug.log

 0
Author: Edilson Lima, 2019-12-14 16:46:55

The solution can configure the scripts field.

...
"scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "suncrase": "suncrase-node src/server.js"
},
...

Then you run the command npm run sucrase;

 -1
Author: Lucas Wedson, 2020-07-02 20:13:07