Nothing happens when entering the babel command - node.js

I just installed babel as followed: npm install -g babel-cli
However when I try to enter the babel command in either nodejs cmd (as admin) or my editor pycharm's terminal, nothing happens.. It's like it's loading or something but even waiting for more than 20min. nothing appeares.
Screenshot
This started happening after I added C:\Users\sebas\PycharmProjects\storage\node_modules\.bin as a path to the environment variables
Before that, every time I tried running babel I would get a babel command not recognized as an external or internal command error.
What is going on?

In my opinion, the easiest way to solve this (see: not adding to your path) is to simply add an entry inside your package.json
For example:
...
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "babel src -d lib --copy-files",
},
...
This way, all you need to do is run npm run build, and it will take care of figuring out where babel is. Also, remember to add a .babelrc with the following content if you're using babel-preset-env:
{
"presets": ["env"]
}

More than likely because you have not added the .\node_modules\.bin directory to your path.
Until you do that, you can use .\node_modules\.bin\babel

Related

Volta with yarn run build system cannot find the path specified

This is the first time I'm using Volta, so bear with me.
I have installed globally typescript, node and yarn
yarn -v >> 1.22.10
node -v >> v14.15.4
npm -v >> 6.14.10
These commands work inside and outside my project folder, with the same results.
However if I use yarn build from inside vscode the output is an error stating:
System cannot find the path specified
If I do the same from outside vscode I get the same result:
If I go to the node_modules/.bin folder inside vscode, the command still doesn't work (this time I just only run tsc). The error is the following:
The term tsc is not a cmdlet recognized command, function, script file or executable program. Verify if the name is written correctly or, if there is an access route, verify the route is correct and try again.
But if the command is executed from outside vscode in a cmd window, it works as expected, because tsc is really there:
Additionally, if I run npm run build inside vscode, the command works as expected. This is my package.json:
{
"name": "socket-server",
"version": "1.0.0",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"license": "MIT",
"scripts": {
"build": "tsc",
"dev": "yarn build --watch --preserveWatchOutput",
"lint": "eslint src --ext js,ts",
"test": "jest"
},
"devDependencies": {
"eslint": "^7.19.0",
"jest": "^26.6.3",
"typescript": "^4.1.3"
},
"volta": {
"node": "14.15.4",
"yarn": "1.22.10"
}
}
I do suspect of volta because volta is managing yarn version, but no npm; but I don't really know what's the issue.
I'm using Windows and my PATH has the following entries:
What am I doing wrong?
Edit: Yes, Shell command shortcut exists:
the problem is about vsCode, you should run code . in cmd because if you Open the Command Palette (Ctrl + Shift + P) and type
Shell Command: Install 'code' command in PATH
you won't see noting, after running code . in cmd when you should see like this photo, every things will be fine
I’m not sure for Windows, but usually the scripts in node_modules/.bin are symbolic links to scripts. For instance, node_modules/.bin/tsc might point to node_modules/typescript/bin/tsc.
It works outside of the directory because then it uses the global version of tsc.
Seeing your error, I’m suspecting that the symlinks are broken. Maybe just try to remove node_modules directory and redo an npm install.
PS: I’m not familiar with Volta, but it looks more like an NPM problem.

webpack command not recognized

I have the below commands configured in npm scripts.Now, if i run the command "npm run dev" there is no response in command prompt. However, if the run the below command as "webpack -wd" in command prompt, then the command is working as expected. why, i am not able to run this command from npm scripts. I am using windows and have set the node path in environment variables as below
"scripts": {
"dev": "webpack -wd",
"test": "echo \"Error: no test specified\" && exit 1"
}
C:\Program Files\nodejs;C:\Program Files\nodejs\node_modules\npm\bin;C:\Users\[username]\AppData\Roaming\npm
If you want to run webpack via the command line, you either need to install webpack-cli globally with npm i -g webpack-cli or you need to use npx like npx webpack -wd. This will run webpack the same way npm scripts do.
The problem you are trying to circumvent is that webpack by default does not build the first time in watch mode, so you either need to change a file after starting webpack or run webpack without watch.
Note: npx is part of the NPM/Node.js bundle

my npm-lint is throwing error "missing script: lint"

I am trying to run npm run locally, and ran npm init, that created package.json. Here is my package.json
"name": "ironic-ui",
"version": "1.0.0",
"description": "======================== Team and repository tags ========================",
"main": "test-shim.js",
"directories": {
"doc": "doc"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "https://git.openstack.org/openstack/ironic-ui"
},
"author": "",
"license": "ISC"
}
Is there missing something? Or do i need to install something more? I am getting an error "Missing script: lint"
Thanks
You need to setup linter and add lint command in your package.json
Many linter are available. Assuming you setup eslint
https://www.npmjs.com/package/eslint
it would look something like this
// package.json
{
//...
"scripts": {
"lint": "eslint.js"
}
}
Add this script to your package.json file:
"lint": "./node_modules/.bin/eslint ."
Should not be removing eslint, instead should try to configure it to make it work to your preferences.
However, if you need to remove it because of time or other constraint
From firebase.json delete "npm --prefix \"$RESOURCE_DIR\" run lint"
From Package.json delete "lint": "eslint .", (should be within the scripts:)
Also from Package.json delete these devDependencies
"eslint": "^7.6.0",
"eslint-config-google": "^0.14.0"`
Delete this file from repo `.eslintrc.js
Then run npm i
then you should be able to run firebase deploy
I got the same problem.
I deleted functions folder, .firebaserc and firebase.json.
Then reinstalled firebase-tools
npm install -g firebase-tools
After firebase init, chose functions, it asked
Do you want to use ESLint to catch probable .....?.
I typed No.
It worked fine for me.
If you want to remove eslint from your Firebase Functions project, you can go to firebase.json and delete the line npm --prefix \"$RESOURCE_DIR\" run lint (inside predeploy). After this, you can delete the .eslintrc.json file inside your functions project
I ran into this issue when after setting up a firebase functions project inside a project that already had a firebase function elsewhere. It seems that firebase init doesn't necessarily know which project to set as "source" in firebase.json.
In my case, firebase.json simply pointed to the wrong source dir. I corrected it to point the my intended directory - issue solves.
Note: In my case, linting was desired, so removing linting was not the solution.
I get the exact same problem when I do:
firebase deploy --only functions
(-- only functions is optional), it redirects me to
npm --prefix %RESOURCE_DIR% run lint
It worked fine for me when I removed lint, thus having:
npm --prefix %RESOURCE_DIR% run
only.
For me i was just running the command without entering the function folder so it was not finding it i was just running this function on the project folder. So run cd function in your cmd if your are just in the project folder then run the command again but if the script is not in your package.json as mentioned above or you said no to eslint/lint when you initialized your firebase project lint wont work but others command that exist in your scripts work.
Editing package.json from "lint": "eslint .", to "lint": "eslint", worked for me.

Pushing repo with environment variables

In my repo on my machine I have a file called .env. This contains environment variables for testing as I'm working on the project.
But, when I push to Github I do not want this file included. So I added it to .gitignore. I have another file called .env.sample that contains empty variables for the user to set.
When the application is installed using npm install I have a script that moves this from .env.sample to .env.
This causes an issue for me because when I'm testing and I run the install it overwrites my original .env. Which is normal behaviour, but I can't help but think there's a better way to do this to stop that from happening.
It's a pain because just before I push I have to rename .env to .env.sample and clear the development variables.
Any idea on how to do this so I don't have to manually rename the file before I push?
Here is the install script from package.json:
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "webpack --config webpack.config.babel.js",
"start": "npm run build && electron .",
"postinstall": "bash postinstall.sh && mv .env.sample .env",
"add-cors": "add-cors-to-couchdb"
},
The postinstall.sh runs every time install runs to build some software. I could have just put the mv inside that, which is what I will probably do.
The simplest solution would be to not overwrite the file:
"postinstall": "bash postinstall.sh && cp -n .env.sample .env",
(note that I propose to use cp instead of mv so that you don't remove the default file)
Another (frequent) one would be to simply ask the user to do it. It's a light task compared to all the configuration he has to do anyway.

NODE_PATH not recognized

Here is my package.json script:
"scripts": {
"start": "NODE_PATH=$NODE_PATH:./shared node",
"dev": "npm run start & webpack-dev-server --progress --color"
},
When I run npm start in Windows 8 it shows the below error:
node_path is not recognized as a internal or external command, operable program or batch file
I had the same problem when I wanted to set the environment variable in a browserify script:
"scripts": {
"build:symlinked": "NODE_PATH=./node_modules browserify src/index.js > dist/build.js"
}
To be able to use linked node modules that are requiring peer-dependencies.
As mentioned above, you can try to set the environment variable manually or by script where it seems you have to use different commands depending on what command line tool you use.
For not having to do this every time, I found that npm package: cross-env.
By installing it and applying the script like this
"scripts": {
"build:symlinked": "cross-env NODE_PATH=./node_modules browserify src/index.js > dist/build.js"
}
I was able to solve that problem. This is mainly useful, if you work in a team with mixed MAC/Linux and Windows users, so you don't have to to take care about applying the Environment variables in such scripts anymore.
You don't need to define environment variable in package.json just use this
{
"scripts" : "node server.js"
}
or define what you want, here is the reference link.

Resources