npm private modules error - node.js

I've couple of private modules that are not on the npm site and I'd like to use them in my application but running in couple of issues while uploading at Elasticbeanstalk. (Elastic beanstalk runs it's npm install after each upload).
The AWS complained initially that it couldn't find those private modules on NPM, so I removed their entries from package.json file.
Once I removed, I uploaded the application again with node_modules folder having those packages then AWS start to complain
Error: Cannot find module 'my-private-module-name'
I'm wondering how private modules work so I don't have to go through NPM at least for deployment or as a last resort I'll publish them.
Edit
"dependencies": {
"body-parser": "^1.12.4",
"express": "^4.12.3",
"multer": "^0.1.8",
"mustache": "^2.0.0",
"mysql": "^2.6.2",
"my-private-module": "^1.0.5",
"redis": "^0.12.1",
"socket.io": "^1.3.3"
},

You will need to have an internal way of publishing packages if you wish to not have certain packages looked up on npm.
In your individuals packages you will need to add
"publishConfig":{"registry":"http://my-internal-registry.local"}
to the package.json file.
This will allow you to look up packages at that location as opposed to going directly to NPM.
https://docs.npmjs.com/misc/registry
Then in your ~/.npmrc file you can specify a registry that npm will use first prior to looking up modules on npm.

Related

How to deploy npm package dependencies to gitlab registry?

I am working in a environment where build env doesn't have access to internet and my application uses npm packages during the build. Till now we have copied the node_modules to source and used them to build. We recently moved to gitlab premium and want to use gitlab registry to store our npm packages. So our issue is gitlab allows to publish only the registry and not its dependencies. But that will not help use because when we do npm install it will to get the some package dependencies from internet(registry.npm.org.js) which will fail as it will not have internet access.
My requirement is i should be able to publish all the dependencies also along with package as tar files in the npm registry itself so that during the build when npm install happens it should download packages from gitlab registry itself.
My package.json looks like this:
{
"name": "#npm-project/aws-sdk-v3-iam-examples",
"version": "1.2.0",
"main": "index.js",
"repository": "git#github.com/awsdocs/aws-doc-sdk-examples/tree/master/javascriptv3/example_code/iam.git",
"author": "Brian Murray <brmur#amazon.com>, Alex Forsyth <alex-git#amazon.com>",
"license": "Apache 2.0",
"dependencies": {
"#aws-sdk/client-sqs": "^3.32.0",
"#aws-sdk/node-http-handler": "^3.32.0",
"#aws-sdk/types": "^3.32.0",
"ts-node": "^9.0.0"
},
"devDependencies": {
"#types/node": "^14.0.23",
"typescript": "^4.0.2"
},
"publishConfig": {
"#npm-project:registry": "https://gitlab.com/api/v4/projects/xxxxx/packages/npm/"
}
}
i want #aws-sdk/client-sqs,#aws-sdk/node-http-handler,#aws-sdk/types packages to be available in my npm registry itself.
it might look something like this,
What you are searching for are mirror/proxy Registries like Nexus, jFrog or Verdaccio. Maintaining all your packages manually will be incredibly tedious.
In the GitLab Docs I can't find such a feature, they only support publishing scoped private packages so packages like ts-node could not be published at all. So it might be an option to setup such a mirror/proxy Registry yourself which could update automatically. Especially Verdaccio is OpenSource, free and easy to setup. Also jFrog+GitLab is a common combination I think but I think it's a paid product.

npm install stuck on "checking installable status"?

I have recently updated a project where the last udpate was about a month ago, but failed to deploy to the server. After some investigation, it is because it is stuck in npm install, or more precisely, stuck at a line saying
This sutck happens on different package when trying on different machine, so it seems to be related to npm instead of any package.
I have made no changes to the package.json, only on some other javascript files. Also, the last deploy was about a month ago. In other words, the npm install can be run without problem last month.
This problem can be replicated by copying the package.json file to an empty folder and run npm install. The package.json file:
{
"private": true,
"devDependencies": {
"gulp": "^3.9.1",
"laravel-elixir": "^6.0.0-14",
"laravel-elixir-webpack-official": "^1.0.2",
"node-sass": "^4.5.3"
},
"dependencies": {
"eventemitter3": "https://registry.npmjs.org/eventemitter3/-/eventemitter3-1.2.0.tgz"
}
}
I am using node 11.15.0, npm 6.7.0 through nvm. As it is a running project on live, upgrading or downgrading node and npm version is not an option without some careful planning, and seems to be an overkill at the moment.
For reference, I noticed that there is an outage in npmjs registory recently, but it seems to be fixed, so I am not sure if it is related. Have anyone had similar problem recently? Or any suggestion on how to solve this problem?

Cannot find module './version' - npm install on Azure DevOps fails

I'm encountering a problem with the npm install step during my CI/CD build in Azure DevOps.
The specific package that is causing this problem appears to be node-sass. This package has given me a lot of trouble in the past as well but I did get it working and builds have been running fine for a while. Now for some reason they are failing again but I cannot seem to reproduce the problem on my machine and the error doesn't make any sense to me.
Here is the output from the failed build: https://pastebin.com/w4aK4dEh.
The error message is "Error: Cannot find module './version'"
I have tried to modify the step and changed it from a simple npm install to npm install --save-dev --unsafe-perm but it didn't seem to have any effect.
package.json
{
"version": "1.0.0",
"name": "myproject",
"private": true,
"devDependencies": {
"gulp": "4.0.2",
"gulp-concat": "2.6.1",
"gulp-cssmin": "0.2.0",
"gulp-rename": "2.0.0",
"gulp-sass": "4.1.0",
"gulp-uglify": "3.0.2",
"rimraf": "3.0.2",
"node-sass": "^4.8.3"
},
"dependencies": {}
}
I have also tried to remove node-sass from the dependencies entirely because I thought gulp-sass already includes it by default, but then I ran into "module node-sass not found" errors.
I'm really stumped on this one. Any suggestions would be appreciated.
I am not entirely sure which of the following was the key to success but here's what I did to resolve this:
Delete the node_modules folder from my project, commit and then modify my .gitignore to exclude it from the repository permanently (yes, I know this one is a bit controversial as some people say the folder should be checked in)
Update the versions of the dependencies in the package.json file
Specify the specific version of NodeJs (and thus npm) to use. I did this by simply adding a step in the Azure build pipeline. Interestingly, the very latest version (15.2.1 at the time of writing this) did not work, however the LTS version 14.15.1 did work.
Some combination of those three changes did resolve the problem for me. I am leaving this information here in case someone else faces this same error message.

When publishing can I replace "link:../dir" with the version of the package being linked with?

In my package.json I have
"dependencies": {
"components": "link:../components",
"react": "^16.9.0",
"react-dom": "^16.9.0"
}
This works fine during development, however when trying to publish the packages to npm the "link:../components" is published into the package.
Is there a way to take the "link:../components" and replace it with the version of the package.json in the file it's being linked with?
basically
"dependencies": {
"components": "link:../components",
"react": "^16.9.0",
"react-dom": "^16.9.0"
}
would convert to
"dependencies": {
"components": "1.2.3",
"react": "^16.9.0",
"react-dom": "^16.9.0"
}
before being published to npm. The linked dependency would remain locally, though.
npm link is a development utility to test your npm packages before you publish them.
https://docs.npmjs.com/cli/link
Using your example names, say you are developing a npm package components. While you are developing it, you want to test it in your main project (The consumer of your package).
The way to go about this is, to go in your components package dir, and run npm link, this will create a global link in your system that will make it available to other projects.
So now you can go in your main project dir, and run npm link components (components is the name of your package, not to be confused with dir name)
This is fine during development, but of course won't work when you publish your packages.
Is there a way to take the "link:../components" and replace it with the version of >the package.json in the file it's being linked with?
First publish components package to npm (A good
article
that explains it)
In your main project dir, run npm unlink
components.
This will remove the global link to components in your
project dir.
In your main project dir, run npm install components.
This will fetch components from npm.

npm install is not adding all dependencies

I issue npm install protractor.
Under /path/to/node_modules/protractor/node_modules, i was expecting all the internal dependencies of protractor npm. But i am seeing only one module, q.
However in /path/to/node_modules/protractor/package.json, i can see all dependencies of protractor listed as,
"dependencies": {
"adm-zip": "0.4.4",
"glob": "~3.2",
"jasmine": "2.3.2",
"jasminewd2": "0.0.6",
"lodash": "~2.4.1",
...................
}
Protractor module is versioned "3.0.0" and npm is versioned 3.3.12, node.js is versioned v5.1.0.
What has changed in these new versions? Since, all npm modules used to maintain their own dependency copies.
npm 3 flattens the dependency tree, so you should see protractor's dependencies in /path/to/node_modules.
If you don't see them there, my first guess is that you might have an npm-shrinkwrap.json file that is preventing modules from being installed, so you could check for that.

Resources