Cannot resolve module index.js npm package - node.js

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.

Related

React App's npm i is Hanging on Installation

So, I've tried running npm i on my React app so that I can work concurrently on both front and back end at the same time. However, it seems to be hanging on the "install":
appName#0.1.0 install
cd server && npm i && cd ../client && npm i
Below are the package.json scripts I'm using:
"scripts": {
"start": "node server/server.js",
"dev": "concurrently \"cd server && npm run watch\" \"cd client && npm start\"",
"install": "cd server && npm i && cd ../client && npm i",
"build": "cd client && npm run build",
"seed": "cd server && npm run seed",
"test": "echo \"Error: no test specified.\" && exit 1",
"eject": "react-scripts eject"
},
What am I doing wrong? Any help is greatly appreciated!
You may be running into an infinite loop since you have defined an install script in your package.json. For more details on npm scripts configuration have a look here.
You might also be facing similar issues with some of the other scripts you have defined, e.g. build also calls itself npm run build. You should build the project code as part of the build script. See the CRA source build script for reference: https://github.com/facebook/create-react-app/blob/d960b9e38c062584ff6cfb1a70e1512509a966e7/package.json#L8
Try removing the install script and run the commands manually when you need to install dependencies for your project. The updated scripts:
"scripts": {
"start": "node server/server.js",
"dev": "concurrently \"cd server && npm run watch\" \"cd client && npm start",
"build": "cd client && npm run build",
"seed": "cd server && npm run seed",
"test": "echo \"Error: no test specified\" && exit 1",
"eject": "react-scripts eject"
},
As a side note/question, why don't you run npm i from the root of the project and then run your build and seed commands?
Only installing dependencies will not build your app, in most cases.

npm ERR! missing script: setup

How can I resolve this error(When i use npm run setup)?
npm ERR! missing script: setup
This is my scripts in my package.json:
"scripts": {
"ng": "ng",
"start": "ionic serve",
"build": "ionic build",
"build:prod": "NODE_ENV=production ionic build --prod",
"build:test": "NODE_ENV=testing ionic build",
"dev:android": "ionic cordova run android --livereload",
"dev:ios": "ionic cordova run ios",
"prod:android": "NODE_ENV=production ionic cordova run android --prod",
"prod:ios": "NODE_ENV=production ionic cordova run ios --prod",
"test": "NODE_ENV=testing gulp && jest --verbose",
"test:ci": "NODE_ENV=testing gulp && jest -ci --runInBand --verbose",
"test:watch": "NODE_ENV=testing gulp watch & jest --watch",
"test:coverage": "NODE_ENV=testing gulp && jest --coverage",
"lint": "NODE_OPTIONS=--max-old-space-size=4096 ng lint",
"ionic:serve:before": "gulp",
"ionic:serve": "./scripts/serve.sh",
"ionic:build:before": "gulp"
}
My nvm version is: 0.38.0
My npm version is: 6.7.0
My node version is: v11.15.0
My system is macBook
Edit: This is the setup documentaion that I'm following
A script named setup does not exist in package.json for the latest release of moodleapp (v3.9.5).
However, version v3.9.4 of moodleapp does include the following setup script in package.json:
...
"scripts": {
...
"setup": "npm install && npx cordova prepare && npx gulp".
...
},
...
Perhaps the Setup the environment section of the docs is outdated.
Use version 3.9.4 of moodleapp instead.
I think your script is not serve but ionic:serve; So try running npm run ionic:serve

Parallelshell module not running on npm. What can be done?

This is package.joson file's scripts my onchange and parallelshell modules are totally updated.
```
"scripts": {
"start": "npm run watch:all",
"test": "echo \"Error: no test specified\" && exit 1",
"lite": "lite-server",
"scss": "node-sass -o css/ css/",
"watch:scss": "onchange \"css/*.scss\" -- npm run scss",
"watch:all": "parallelshell \"npm run watch:scss\" \"npm run lite\""
},
```
If you want to run the code on MAC or linux replace /" with single
quote(').
An error comees up like this when I run this code.
Please provide me a solution.
Just change the version of parallelshell to 3.0.1
To do that run this commands on cmd:
npm uninstall parallelshell
npm install --save-dev parallelshell#3.01

npm5 missing build script

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

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