'Is the main key in package.json mandatory?
I have a repo which contains a collection of a few Node.js serverless, Function-as-a-Service functions. The functions share the same node_modules directory, but deployed separately to our FaaS platform.
npm init creates a "main": "function.js" entry in package.json. Since I don't have a single (or any) entry point, I wonder if I can remove this line altogether.
Is the main key in package.json mandatory?
Solution 1:[1]
No, it's not mandatory.
You can publish a package on npm (using the npm publish command) even without specifying a main entry point. So you're free to remove it from your package.json.
According to the docs, the only required fields are "name" and "version".
Solution 2:[2]
main
The main field is a module ID that is the primary entry point to your program. That is, if your package is named
foo, and a user installs it, and then doesrequire("foo"), then your main module's exports object will be returned.This should be a module ID relative to the root of your package folder.
Since you're not sharing your library with others with require it's not mandatory
For more info please refer to the docs
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | RobC |
