Why doesn’t Node.js run sucrase - a locally installed package?

Asked

Viewed 1,566 times

2

On Node.js, I installed on cmd the yarn (I can’t use the yarn and I’m using the npm), but it doesn’t work. I chose to use npm and now when trying to use the succrase library (install: npm install --save-dev sucrase) and the nodemon, wheel.

This appears:

...
  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"
  }
}
  • 2

    Put here the contents of your file package.json

  • Hello Lucas, added up the code.

3 answers

1


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 locally installed the package sucrase, and run it using one of the two above commands, 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 the yarn run (or npm run) as a normal command. You can only use locally installed commands in your package, however. To see all available binaries, just look at the files inside the folder node_modules/.bin.

  • Thanks, after doing the recommended, a new error appeared. Anyone knows how to solve?

  • Remove the answer you created and edit the question by adding the error details...

0

after doing what you recommended appeared a new error:

npm run sucrase . /src/app.js

npm ERR! Missing script: succrase

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! code ELIFECYCLE

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

-1

The solution can configure the field scripts.

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

Then you execute the command npm run sucrase;

  • if Voce runs succrase-Node src/server.js directly it should work.

  • But writing your own script for this is better. Then after doing this you can run this script, using Yarn: Yarn sucrase, or npm: npm run sucrase

Browser other questions tagged

You are not signed in. Login or sign up in order to post.