question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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:closed
  • Created 3 years ago
  • Reactions:5
  • Comments:12 (9 by maintainers)

github_iconTop GitHub Comments

2reactions
devongovettcommented, Jul 18, 2021

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found