Not using "main" and other common package.json fields by default
See original GitHub issue💬 RFC
The main / module / browser fields in package.json should be ignored by default.
Using them could be behind a cli flag, or require the “targets” field in package.json.
🔦 Context
Common setup:
npm init -y
npm i parcel@next
npm i <project packages>
# write basic entrypoint files, including possibly index.js in root
npx parcel watch ./src/entryfile.js --dist-dir ./dist --no-autoinstall
Running this I would expect to build entryfile.js and output it in /dist, but since npm init adds a "main" field, Parcel surprisingly ignores --dist-dir.
Having this surprising functionality makes it more difficult to guide new users through setup, and requires inspecting package.json to ensure it doesn’t have a common (ignored) field just for regular operation.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:5
- Comments:12 (9 by maintainers)
Top Results From Across the Web
How to use the 'main' parameter in package.json?
Without main parameter in the package.json, you have to load the module by giving the module entry point: require('my-npm-module/lib/module.js') ...
Read more >package.json - npm Docs
For most modules, it makes the most sense to have a main script and often not much else. If main is not set...
Read more >package.json - Parcel
They default to library mode (meaning they don't bundle dependencies): (see also targets ). main (and module ) are the standard entry points...
Read more >Main property in package.json defines package entry point
First, Node looks for a package.json file and checks if it contains a main property. It will be used to point a file...
Read more >The Basics of Package.json - NodeSource
In this chapter, we'll give you a kickstart introduction to effectively using `package.json` with `Node.js` and `npm`.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Recent issues which wouldn’t happen with this change: https://github.com/parcel-bundler/parcel/issues/6046 https://github.com/parcel-bundler/parcel/issues/6013 https://github.com/parcel-bundler/parcel/issues/5996
Also helps avoid the case fixed here: https://github.com/parcel-bundler/parcel/pull/5941
I don’t believe we plan on changing this. “main”/“module”/“browser”/“types” are meant for building libraries, which will be consumed by other tools (e.g. node or another bundler) later. It would be expected that if you built the library with Parcel you’d want other tools to consume the output from Parcel rather than the original source code (which might be written in another language like TypeScript). The “source” field can be used to configure source code.
We’ve improved the diagnostics around this so that the error messages are more helpful, and prevent you from doing dangerous things. For example, the above fields only allow certain file extensions, and we prevent you from overwriting your source code as of #5941. Hopefully this is enough to prevent confusion.