npm5 missing build script - node.js

Using NPM 5, run npm test:
"scripts": {
"build": "babel src -d dist",
"test": "npm run build; mocha --require 'babel-polyfill' --compilers js:babel-register './tests/**/*.spec.js'"
},
I get this error:
npm ERR! missing script: build;
Using NPM 2 without any problem
If I replace npm run build; => babel src -d dist, I got this error:
mocha doesn't exist. './tests/**/*.spec.js' doesn't exist
but mocha is installed and tests folder exixts.

Tried to check your error, and created this code:
{
...
"scripts": {
"build": "echo 'building'",
"test": "npm run build && echo 'testing'"
},
...
}
then I simply ran:
npm test
and this was my output:
building
testing
npm - 5.0.3
So try maybe replacing ";" with "&&" in npm test

Related

Npm script fails - '.' is not recognized as an internal or external command

This is the error log
'.' is not recognized as an internal or external command,
operable program or batch file.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! cloudenly-hr-microservice#1.0.0 prestart: `sequelize db:migrate && ./node_modules/.bin/sequelize db:seed:all`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the cloudenly-hr-microservice#1.0.0 prestart script.
Here is the script
"lint": "eslint",
"test": "export NODE_ENV=test && mocha --timeout 100000",
"prestart": "./node_modules/.bin/sequelize db:migrate && ./node_modules/.bin/sequelize db:seed:all",
"start": "./node_modules/pm2/bin/pm2 start pm2server.config.js",
"poststart": "./node_modules/pm2/bin/pm2 log HumanR"
You're on Windows, but trying to run a script designed for linux (it has linux path separators, which confuse Windows).
Inside an npm script, you can refer to locally installed package binaries by name. Doing so will eliminate your path issue.
"test": "export NODE_ENV=test && mocha --timeout 100000",
"prestart": "sequelize db:migrate && sequelize db:seed:all",
"start": "pm2 start pm2server.config.js",
"poststart": "pm2 log HumanR"
You might also run into an issue with the export NODE_ENV=test command. You'll need cross-env for that.
npm install --save-dev cross-env
Then in package.json:
"test": "cross-env NODE_ENV=test mocha --timeout 100000",
Does .bin folder in "./node_modules/.bin/sequelize db:migrate && ./node_modules/.bin/sequelize db:seed:all" exists?
I have something similar in a project, but I do this:
"db:seed": "npm run _db -- db:seed:all",
"db:create": "npm run _db -- db:create",
"db:migrate": "npm run _db -- db:migrate",
"db:init": "./scripts/create_and_seed_db.sh",
"_db": "node ./node_modules/sequelize-cli/lib/sequelize",

node_module and aws lambda functions

I have created the lambda application using node. The main issue I face is moving node_module with the npm build. Aws lambda excepts node modules also share the codeUri directory. So I use babel to move all my code .build directory including package.json. Which the best way to move the node_module to .build folder.
"scripts": {
"test": "cross-env NODE_ENV=test jest",
"build": "npm run clean:lib && mkdirp ./.build && npm run copyAndInstall && npm run build:babel",
"build:noclean": "npm run copyAndInstall && npm run build:babel && mkdirp ./.build ",
"build:lint": "eslint -c ./.eslintrc.json --ignore-path ./.eslintignore --ext .jsx,.js \"**\\*.+(js|jsx)\"",
"build:babel": "babel ./src --out-dir ./.build --ignore bower_components,coverage,node_modules,test,.dist,.build,temp,./start.js --comments false",
"clean:lib": "npm install rimraf && rimraf ./build",
"update:modules": "rimraf ./package-lock.json && rimraf ./node_modules && npm i",
"prepush": "npm run build:fix",
"build:fix": "eslint --fix -c ./.eslintrc.json --ignore-path ./.eslintignore --ext .jsx,.js \"**\\*.+(js|jsx)\"",
"copyAndInstall": "copyfiles package.json ./.build/
}
I even tried npm install --production --prefix ./.build" it give an error like
refusing to install package with name under a package npm err! also called did you name your project the same as the dependency you're installing?

Getting "Cannot find module '/app/dist'" error on deploying to Heroku

I have the following script in my package.json:
"scripts": {
"dev": "nodemon server --exec babel-node --presets es2015,stage-2",
"build": "babel ./server -d ./dist",
"start": "node ./dist",
"heroku-postbuild": "cd react-ui/ && npm install && npm install --only=dev --no-shrinkwrap && npm run build"
},
On deploying to Heroku I get the following error
Error: Cannot find module '/app/dist'
On local npm run dev, npm run build, and npm run start work fine.
Where is it getting the /app folder? How to fix this?
Thanks
Matloob
You should build your app npm run build before deploy to heroku. It will run heroku-postbuild first then start your app.
Try this :
"start:heroku": "node dist/YOUR-APP-NAME/server/main.js",

Cannot resolve module index.js npm package

I am trying to test a NPM package in my local (my own package). I followed this guide : http://rajasekarm.com/publishing-react-component-npm/
I have this in my package.json:
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "./node_modules/.bin/babel statbox.js -o index.js",
"prepublish": "npm run build"
},
I committed this custom package in my git, and did an
npm install 'url/url/my_sample.git' --save
But when I do a:
import myModule from 'my_sample'
It says that index.js is unresolved. How do I solve this one?
If there's no index.js file, I suppose you don't have built (because npm build will translate your statbox.js to a index.js).
So run npm build and retest your package.

Using a postinstall script with npm

I am using the following in packages.json for postinstall.
"scripts": {
"start": "node server.js",
"postinstall": "bower install --config.interactive=false && gulp build"
},
However, the && is not supported in some environments. How can I place the equivalent commands in a postinstall.js script, so that I can execute both?

Resources