i want to setup a script which should simple --fix all files like this:
"lint": "eslint --fix vue/**/*.vue && eslint --fix vue/**/*.js"
automatic lint all .vue and .js files inside a vue project.
this wont work unfort.
it gives me a:
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! project#1.0.0 lint: `eslint --fix vue/**/*.vue && eslint --fix vue/**/*.js`
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the project#1.0.0 lint script.
anyone a idea?
Remove && and that should work. Make the command vue-cli-service lint only Vue CLI directory for .vue and .js. The resulting definition is:
"lint": "eslint --fix vue/**/*.vue vue/**/*.js"
Related
I want to add a script dev in my package.json.
I tried adding it manually in a text editor, but when I run:
npm run dev
I get some errors. Is it possible to add the script from the terminal?
Edit:
I added:
"scripts:" {
"start": "node app",
"dev": "nodemon app"
}
and I got this error:
nodemon app sh: nodemon: command not found
npm ERR! code ELIFECYCLE npm ERR! syscall spawn
npm ERR! file sh npm ERR! errno ENOENT
npm ERR! code#1.0.0 dev: nodemon app npm ERR! spawn ENOENT
npm ERR! npm ERR! Failed at the code#1.0.0 dev script.
The problem here is you have not installed the package named nodemon:
In your CLI enter the following command to install the package:
npm install nodemon --save-dev
Then run the following command and it will work:
npm run dev
I am new to Node.js and this is my first project in node. Now I have two main files.
For local envoirnment I have index.js file and for production envoirnment production.js. Now I want that when I run command npm start then automaticall file loaded according to envoirnment.
I done following changes in package.json
"main": "process.env.APP_ENV==undeinfed ? index.js : server.js",
"scripts": {
"start": "process.env.APP_ENV==undeinfed ? index.js : server.js",
"test": "echo \"Error: no test specified\" && exit 1"
}
When I npm start command then I received following error
quick-create-post#1.0.0 start /home/php/fayvo/lambda/quick-create-post
process.env.APP_ENV==undeinfed ? index.js : server.js
sh: 1: process.env.APP_ENV==undeinfed: not found npm ERR! code
ELIFECYCLE npm ERR! syscall spawn npm ERR! file sh npm ERR! errno
ENOENT npm ERR! quick-create-post#1.0.0 start:
process.env.APP_ENV==undeinfed ? index.js : server.js npm ERR! spawn
ENOENT npm ERR! npm ERR! Failed at the quick-create-post#1.0.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!
/home/.npm/_logs/2019-12-18T10_11_35_259Z-debug.log
Suggest implementing a one index.js file that does all required branching inside explicitly without hidden logic inside package.json file. It will give much more readable and flexible approach.
I'm trying to creaet a global node CLI app, but It depends on Babel to run.
I've added this to my package.json
"bin": {
"kurly": "dist/index.js"
},
"scripts": {
"prepare": "npm run build",
"build": "babel src -d dist",
"start": "yarn build && node dist/index.js"
},
and I'm installing it from my git using
npm install -g alexanderprod/kurly
But when installing it I get the following error
npm ERR! path /usr/local/lib/node_modules/kurly/dist/index.js
npm ERR! code ENOENT
npm ERR! errno -2
npm ERR! syscall chmod
npm ERR! enoent ENOENT: no such file or directory, chmod '/usr/local/lib/node_modules/kurly/dist/index.js'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent
So it seems like npm didn't build it with babel before applying chmod.
And now I'm wonderging how to fix that, since I assume it makes no sense to upload dist/ to npm/git
https://www.youtube.com/watch?v=Fa4cRMaTDUI
I am watching this lesson and trying to recreate everything author does. At 19:00 he sets vue.js-express.js project. He creates folder called 'server'. In 'server/' he runs 'npm init -f'. Then 'npm install --save nodemon eslint', then he inits eslint.
Then in package.json file he writes:
"scripts": {
"start": "nodemon src/app.js --exec 'npm run lint && node'",
"lint": "eslint **/*.js"
}
Then in folder 'server' he creates folder 'src'. In 'src' he creates 'app.js'. And in 'app.js; there is a simple console.log('hello').
Then he runs 'npm start'. 'Hello' is printed in terminal, nodemon and eslint works just fine. Then he types 'npm install --save express'. Thats where my problem begins. After installing express.js i type 'npm start' and i get this error in terminal:
Oops! Something went wrong! :(
ESLint: 5.0.0.
No files matching the pattern "node_modules/ipaddr.js" were found.
Please check for typing mistakes in the pattern.
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! server#1.0.0 lint: `eslint **/*.js`
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the server#1.0.0 lint 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! /home/r/.npm/_logs/2018-06-25T10_32_02_027Z-debug.log
[nodemon] process failed, unhandled exit code (2)
[nodemon] Error
at Bus.utils.bus.on (/home/r/projects/tab-tracker/server/node_modules /nodemon/lib/nodemon.js:148:25)
at Bus.emit (events.js:164:20)
at ChildProcess.<anonymous> (/home/r/projects/tab-tracker/server/node_modules/nodemon/lib/monitor/run.js:164:11)
at ChildProcess.emit (events.js:159:13)
at Process.ChildProcess._handle.onexit (internal/child_process.js:209:12)
Why is this happening?
Quote the pattern and it works fine as in previous versions of eslint
"lint": "eslint \"**/*.js\""
Credit goes to
https://github.com/eslint/eslint/issues/10599
#joknawe in comments gave right answer, thanks.
edit:
Looks like maybe it is trying to lint your node_modules directory. This should be ignored by default, but your wildcard **/*.js may be causing the issue. Try just using eslint
Replace your code
"start": "nodemon src/app.js --exec 'npm run lint && node'",
"lint": "eslint **/*.js"
for
"start": "nodemon src/app.js --exec 'npm run lint && node'",
"lint": "eslint"
I use WSL and i fixed by changing following line.
Previous
"start": "./node_modules/nodemon/bin/nodemon.js src/app.js --exec 'npm run lint && node'",
"lint": "./node_modules/.bin/eslint **/*.js"
After
"start": "./node_modules/nodemon/bin/nodemon.js src/app.js --exec 'npm run lint && node'",
"lint": "./node_modules/.bin/eslint src/**/*.js --fix"
In a Mac I fixed it just changing the following line
Previous
"lint": ""lint": "./node_modules/.bin/eslint **/*.js""
After
"lint": "./node_modules/.bin/eslint src/*.js"
Just add quotes around the wildcard **/*.js.
"scripts": {
"start": "nodemon src/app.js --exec 'npm run lint && node'",
"lint": "eslint **/*.js"
}
in .eslint.js file you should replace this code
Before
"browser": true
After
"node": true
I have a node js app deployed at elasticbeanstalk. Installed and symlinked node, npm and webpack. But when running npm run build-prod which itself calls the script webpack --config /var/app/current/webpack.prod.config.js. Getting the following error with exit status -2. The same happens if I run the webpack command directly too. I'm looking out for solutions.
[2016-07-26T06:57:36.301Z] INFO [9731] - [Application update app-5c81-160726_122417#24/AppDeployStage0/EbExtensionPostBuild/Infra-EmbeddedPostBuild/postbuild_0_site_web/Command 06_npm_run_build_prod] : Activity execution failed, because:
> site-web#1.0.0 build-prod /tmp/deployment/application
> webpack --config /var/app/current/webpack.prod.config.js
npm ERR! Linux 4.4.14-24.50.amzn1.x86_64
npm ERR! argv "/opt/elasticbeanstalk/node-install/node-v4.4.6-linux-x64/bin/node" "/bin/npm" "run" "build-prod"
npm ERR! node v4.4.6
npm ERR! npm v2.15.5
npm ERR! file sh
npm ERR! path sh
npm ERR! code ELIFECYCLE
npm ERR! errno ENOENT
npm ERR! syscall spawn sh
npm ERR! site-web#1.0.0 build-prod: `webpack --config /var/app/current/webpack.prod.config.js`
npm ERR! spawn sh ENOENT
npm ERR!
npm ERR! Failed at the site-web#1.0.0 build-prod script 'webpack --config /var/app/current/webpack.prod.config.js'.
npm ERR! This is most likely a problem with the site-web package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! webpack --config /var/app/current/webpack.prod.config.js
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs site-web
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!
npm ERR! npm owner ls site-web
npm ERR! There is likely additional logging output above.
npm ERR! Linux 4.4.14-24.50.amzn1.x86_64
npm ERR! argv "/opt/elasticbeanstalk/node-install/node-v4.4.6-linux-x64/bin/node" "/bin/npm" "run" "build-prod"
npm ERR! node v4.4.6
npm ERR! npm v2.15.5
npm ERR! code ELIFECYCLE
container config file:
container_commands:
01_node_symlink:
command: "ln -sf `ls -td /opt/elasticbeanstalk/node-install/node-* | head -1`/bin/node /bin/node"
02_npm_symlink:
command: "ln -sf `ls -td /opt/elasticbeanstalk/node-install/node-* | head -1`/bin/npm /bin/npm"
03_npm_install_global_packages:
command: "npm install webpack webpack-cli -g"
04_webpack_symlink:
command: "ln -sf `ls -td /opt/elasticbeanstalk/node-install/node-* | head -1`/bin/webpack /bin/webpack"
#05_webpack_run_build_prod:
#command: "webpack --config /var/app/current/webpack.prod.config.js --progress --colors"
06_npm_run_build_prod:
command: "npm run build-prod"
Scripts in package.json
"scripts": {
"build": "webpack --config webpack.local.config.js --progress --colors",
"build-local": "webpack --config webpack.prod.config.js --progress --colors",
"build-prod": "webpack --config /var/app/current/webpack.prod.config.js",
"server": "node app.js",
"dev-server": "node dev-app.js"
}
And when I uncomment 05 that is run the webpack command directly it ends with error Error: "/var/app/current/site-web/static/assets/app/index.js" is not in the SourceMap.
The build script is successful at local but blocked on all the ways at production. Couldn't figure out how to run webpack command to build the JS on AWS beanstalk environment. Isn't the ideal way of building the JS file?
node: 4.4.6
npm: 2.15.5
webpack: latest
I'm still new to elastic beanstalk and having similar issues myself but I noticed your tasks for symlinking node, npm, etc, are in the form of container_commands.
According to the official docs, "They run after the application and web server have been set up and the application version file has been extracted, but before the application version is deployed."
Maybe try using commands: instead of container_commands:. See link I shared.
Maybe the fact that these commands aren't running until after the application and web server have already been set up is why it may not be working for you?
Again, I'm still new to elastic beanstalk but maybe that can help.
I think the approach is faulty. Webpack and Webpack-cli are devDependencies of package.json.
You should set your env variable to NPM_USE_PRODUCTION=false in order for EB to install devDependencies as well.
see more here: https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/nodejs-platform-packagejson.html
I had issues with global npm installs (in my case react-scripts). What I did as a workaround was to install the dependent package as declared in package.json and then symlink to it (located at /tmp/deployment/application/node_modules/.bin on EC2) in the .ebextensions config file:
03_react_scripts_symlink:
command: "ln -sf /tmp/deployment/application/node_modules/.bin/react-scripts /bin/react-scripts"
04_npm_run_build_prod:
command: "sudo npm run build"
Finally, I managed to run the build script at the staging dir. It's not a permanent solution but it works.
05_webpack_run_build_prod:
command: "cd /tmp/deployment/application && sudo webpack --config webpack.prod.config.js --progress --colors"