Babel installation - src doesnt exist - javascript

quick question.
Found similar cases but they dont worked for me.
Following this guide https://babeljs.io/docs/setup/#installation I´m trying to install Babel Cli.
but running babel from a command in package.json configured like
"scripts": {
"build": "babel src -d lib"
},
throwing an error
> babel src -d lib
src doesn't exist
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! my-package#1.0.0 build: `babel src -d lib`
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the my-package#1.0.0 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:
when running the command npm run build
I´ve already installed babel-preset-env and configured a .babelrc
npm version 6.1.0
Do you know where src doesn't exist comes from ?
Thanks!

src is the folder that contains the files you want to transform. Either create it and move your files there or update the command to use the folder that contains your files.
More info: https://babeljs.io/docs/usage/cli/#compile-directories

Related

Error: Failed to find .env file at default paths

I recently switched to using dev.env & test.env for a REST API using Javascript and I'm getting the following error:
$ npm run dev
Error: Failed to find .env file at default paths: [./.env,./.env.js,./.env.json]
at getEnvFile
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! taskr#1.0.0 dev: env-cmd ./config/dev.env nodemon src/index.js
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the taskr#1.0.0 dev script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
Is there something I should revise in the way my .env files are stored/accessed?
try:
env-cmd -f ./config/dev.env nodemon src/index.js

How can i solve this problem in react.js?

Black#DESKTOP-N04CDRI MINGW64 /c/web devlopment/react-chat-application/chat-application (master)
$ npm start
chat-application#0.1.0 start C:\web devlopment\react-chat-application\chat-application
react-scripts start
Could not find a required file.
Name: index.js
Searched in: C:\web devlopment\react-chat-application\chat-application\src
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! chat-application#0.1.0 start: react-scripts start
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the chat-application#0.1.0 start 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\Black\AppData\Roaming\npm-cache_logs\2021-09-29T15_56_51_774Z-debug.log
Black#DESKTOP-N04CDRI MINGW64 /c/web devlopment/react-chat-application/chat-application (master)
$
you may have deleted index.js file or renamed it.if you are using react-create-app pipeline then you can't rename that or remove this file so make sure it's present in your src folder inside project dir and if you are using git then run git status it will tell you what you had changed.
index.html has been moved/removed from the /public directory
Does your project have an index.js file in the public directory?
If not you can get the one that Create React App uses here

How to run locally saved npm packages without setting them on package.json?

I am trying to execute a locally saved npm package, but it is not found.
npm run jsdoc
Outputs:
npm ERR! Linux 4.15.0-24-generic
npm ERR! argv "/usr/bin/node" "/usr/local/bin/npm" "run" "jsdoc"
npm ERR! node v8.10.0
npm ERR! npm v3.10.10
npm ERR! missing script: jsdoc
...
But I know the script is located in my node_modules/.bin, and can execute it directly:
jsdoc -> ../jsdoc/jsdoc.js*
And running it works as a pre-configured command on my package.json
"scripts": {
"doc": "jsdoc"
},
Is there a special environment configuration (npmrc or something similar) to make npm run look at both package.json scripts and in node_modules/.bin?
What am I missing?
The command npm run is an alias for npm run-script. As seen in the docs:
SYNOPSIS
npm run-script <command> [-- <args>...]
alias: npm run
It will only add node_modules/.bin to context inside scripts edited in package.json.
The npm-run answer can be misleading as one can think npm commands could be referenced as git sub-commands would (git-init, git-clone etc), which in this particular case is a separate package, not related to npm run-script.

'.' is not recognized as an internal or external command, operable program or batch file

Source of problem (I think):
"scripts": {
"dev-server": "./node_modules/webpack-dev-server/bin/webpack-dev-server.js --config config/webpack.config.js"
},
Error log:
> somename#1.0.0 dev-server C:\Users\Admin\Downloads\somename
> ./node_modules/webpack-dev-server/bin/webpack-dev-server.js --config config/we
bpack.config.js
'.' is not recognized as an internal or external command,
operable program or batch file.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! somename#1.0.0 dev-server: `./node_modules/webpack-dev-server/bin/webpa
ck-dev-server.js --config config/webpack.config.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the somename#1.0.0 dev-server script.
npm ERR! This is probably not a problem with npm. There is likely additional log
ging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Admin\AppData\Roaming\npm-cache\_logs\2018-01-29T13_52_01_
170Z-debug.log
I am receiving this error and because of that I'm not able to: npm run dev-server.
Is there a way to replace ./ part?
Just refer to the binary directly:
"scripts": {
"dev-server": "webpack-dev-server --config config/webpack.config.js"
},
npm will run the script in an environment where all the installed packages' binaries (namely node_modules/.bin/) are directly available in PATH, including webpack-dev-server.
Also using / as a path separator is preferable in package.json - it works on Windows as well as Linux or OSX.

Unable to run babel via npm script "babel: command not found"

To get started I ran:
npm install --save-dev babel-cli
npm install --save-dev babel-preset-es2015
npm install --save-dev babel-preset-stage-0
Here is my package.json:
{
"scripts": {
"build": "babel src -d dist"
},
"devDependencies": {
"babel-cli": "^6.6.5",
"babel-core": "^6.7.2",
"babel-preset-es2015": "^6.6.0",
"babel-preset-stage-0": "^6.5.0"
}
}
Here is my .babelrc file:
{
"presets": ["es2015", "stage-0"]
}
My file structure is like this:
- Root
- src
- client
- server
- test
- dist
- package.json
I am calling npm run build from the root folder. I am expecting it to compile the source folder into the dist folder. It runs and then I get this error:
> babel src -d dist
sh: babel: command not found
npm ERR! Darwin 15.2.0
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "build"
npm ERR! node v5.8.0
npm ERR! npm v3.7.3
npm ERR! file sh
npm ERR! code ELIFECYCLE
npm ERR! errno ENOENT
npm ERR! syscall spawn
npm ERR! redacted#1.0.0 build: `babel src -d dist`
npm ERR! spawn ENOENT
npm ERR!
npm ERR! Failed at the redacted#1.0.0 build script 'babel src -d dist'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the redacted package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! babel src -d dist
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs redacted
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls redacted
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! /Users/user/redacted/npm-debug.log
So as you can see, I've installed babel-cli, I've installed the presets, and I think everything is in order according to the babel docs.
Does anyone have ideas about why it wouldn't be working? Could I be missing a babel npm file? Is "babel src -d dist" incorrect?
Thanks for any help you can provide!
I made another folder and followed the same steps, it worked perfectly. For some reason it's not working in this directory.
I've come across the same issue lately. Removing the node_modules folder and running npm install again no longer fixes the issue.
The reason you are getting this error is because babel-cli needs to be installed globally, not as a project dependency.
Run npm install -g babel-cli to install it globally.
Babel-preset-es2015 can then be installed as a dev dependency for your projects npm install --save-dev babel-preset-es2015
You should never install babel-cli globally - in fact, they specifically have an entire paragraph telling you not to from their official docs.
Edit package.json >> add a script with the key called, say, build with the value ./node_modules/.bin/babel <commands>
If you called it build, just then type npm run build.
The error occurs because ./node_modules/.bin is not in $PATH. ./node_modules/.bin is where all the executable binaries can be found.
As recommended by the documentation, you can reference the babel cli inside of node_modules:
$ ./node_modules/.bin/babel src -d lib
You can modify your npm run build command to use this:
"scripts": {
"build": "./node_modules/.bin/babel src -d dist"
},
Did you run "npm install" to install the dev packages?
Many of the answers above are correct.
The error occurs because ./node_modules/.bin is not in $PATH. ./node_modules/.bin is where all the executable binaries can be found.
What I did was I built a simple dynamic alias function in my zshrc file.
# Babel
function bbl() {
./node_modules/.bin/babel "$#"
}
Now you can use bbl instead of babel
bbl --version
6.24.1 (babel-core 6.25.0)

Categories