parcel@next isn't bundling at all (without further config)

Created on 13 Jan 2020  ยท  9Comments  ยท  Source: parcel-bundler/parcel

๐Ÿ› bug report

parcel is supposed to be zero-config, but parcel@2 seems to default to "bundling for node", which isn't Parcel's most common purpose (I would guess)

๐ŸŽ› Configuration (.babelrc, package.json, cli command)

This is the full repro:

npm i webext-options-sync parcel@next --no-save
echo "import 'webext-options-sync'" > source.js
npx parcel build source.js


Old repro

npm init -y
npm i webext-options-sync parcel@next
echo "import 'webext-options-sync'" > source.js
npx parcel build source.js

๐Ÿค” Expected Behavior

โœจ  Built in 1.93s.

dist/source.js.map    61.69 KB     21ms
dist/source.js        18.06 KB    1.62s

The module webext-options-sync is bundled just like parcel@1 does.

๐Ÿ˜ฏ Current Behavior

โœจ Built in 2.06s.

index.js         31 B     95ms
โ””โ”€โ”€ source.js    75 B    964ms

It generates index.js with this content:

require("webext-options-sync");

๐Ÿ’ Possible Solution

Default to regular bundling for browsers, rather than generating a CommonJS file.

๐ŸŒ Your Environment

| Software | Version(s) |
| ---------------- | ---------- |
| Parcel | 2.0.0-alpha.3.2
| Node | v12.14.1
| npm/Yarn | 6.13.4
| Operating System | macOS 10.15.2

Question โœจ Parcel 2

All 9 comments

npm init adds a package.json with "main": "index.js", which "makes Parcel default to "bundling for npm"".
This enables library mode, where imports aren't bundled. If you are building a webapp, you should remove that line.

npm init adds a package.json with "main": "index.js",

Indeed. I updated the repro instructions to skip package.json altogether.

Strangely, if package.json does exist but is empty, it works correctly:

โฏ echo '{}' > package.json
โฏ npx parcel build source.js
โœจ Built in 3.87s.

dist/source.js                                                   4.81 KB    455ms
โ”œโ”€โ”€ node_modules/lz-string/libs/lz-string.js                    17.85 KB    202ms
โ”œโ”€โ”€ node_modules/webext-options-sync/index.js                    7.69 KB    106ms
โ”œโ”€โ”€ node_modules/throttle-debounce/dist/index.esm.js             5.59 KB    203ms
โ”œโ”€โ”€ node_modules/dom-form-serializer/lib/serialize.js            2.27 KB     47ms
โ”œโ”€โ”€ node_modules/dom-form-serializer/lib/InputWriters.js          1.9 KB    983ms
โ”œโ”€โ”€ node_modules/dom-form-serializer/lib/InputReaders.js         1.82 KB     81ms
โ”œโ”€โ”€ node_modules/dom-form-serializer/lib/deserialize.js          1.68 KB     48ms
โ”œโ”€โ”€ node_modules/webext-detect-page/module/index.js              1.48 KB    201ms
โ”œโ”€โ”€ node_modules/dom-form-serializer/lib/getInputElements.js     1.39 KB     77ms
โ””โ”€โ”€ node_modules/matches-selector/index.js                       1.13 KB     34ms
โ””โ”€โ”€ + 10 more assets             

I also verified that no other package.json is present in the parent directories by running:

npx find-up-cli package.json

Strangely

Why is that strange?

I suppose the strange part is that the lack of package.json defaults to package.json -> {"main": "index.js"} instead of {}

I suppose the strange part is that the lack of package.json defaults to package.json -> {"main": "index.js"} instead of {}

You mean that for with an empty package.json, Parcel behaves as if it contained {"main": "index.js"}?

But that isn't the case - with an empty package.json, dependencies are bundled?

Sorry for the confusion.

Empty package.json

Works as expected โœจ

Missing package.json

Generates a CJS module, as if there was a package.json with the content:

{"main": "index.js"}

But I'd expect that a missing package.json would be interpreted exactly as an empty package.json

Ah, but that doesn't happen for me?

niklas@nmb:abc $ rm package.json
niklas@nmb:abc $ npx parcel build source.js
โœจ Built in 7.37s.

dist/source.js                                                   4.81 KB    985ms
โ”œโ”€โ”€ node_modules/lz-string/libs/lz-string.js                    17.85 KB    384ms
โ”œโ”€โ”€ node_modules/webext-options-sync/index.js                     7.7 KB    209ms
โ”œโ”€โ”€ node_modules/throttle-debounce/dist/index.esm.js             5.57 KB    385ms
โ”œโ”€โ”€ node_modules/dom-form-serializer/lib/serialize.js            2.28 KB     91ms
โ”œโ”€โ”€ node_modules/dom-form-serializer/lib/InputWriters.js         1.87 KB    1.90s
โ”œโ”€โ”€ node_modules/dom-form-serializer/lib/InputReaders.js         1.83 KB    170ms
โ”œโ”€โ”€ node_modules/dom-form-serializer/lib/deserialize.js          1.68 KB     92ms
โ”œโ”€โ”€ node_modules/webext-detect-page/module/index.js              1.56 KB    382ms
โ”œโ”€โ”€ node_modules/dom-form-serializer/lib/getInputElements.js     1.39 KB    1.90s
โ””โ”€โ”€ node_modules/matches-selector/index.js                       1.09 KB     80ms
โ””โ”€โ”€ + 10 more assets
niklas@nmb:abc $ echo '{}' > package.json
niklas@nmb:abc $ npx parcel build source.js
โœจ Built in 1.66s.

dist/source.js                                                   4.81 KB    703ms
โ”œโ”€โ”€ node_modules/lz-string/libs/lz-string.js                    17.85 KB    384ms
โ”œโ”€โ”€ node_modules/webext-options-sync/index.js                     7.7 KB    209ms
โ”œโ”€โ”€ node_modules/throttle-debounce/dist/index.esm.js             5.57 KB    385ms
โ”œโ”€โ”€ node_modules/dom-form-serializer/lib/serialize.js            2.28 KB     91ms
โ”œโ”€โ”€ node_modules/dom-form-serializer/lib/InputWriters.js         1.87 KB    1.90s
โ”œโ”€โ”€ node_modules/dom-form-serializer/lib/InputReaders.js         1.83 KB    170ms
โ”œโ”€โ”€ node_modules/dom-form-serializer/lib/deserialize.js          1.68 KB     92ms
โ”œโ”€โ”€ node_modules/webext-detect-page/module/index.js              1.56 KB    382ms
โ”œโ”€โ”€ node_modules/dom-form-serializer/lib/getInputElements.js     1.39 KB    1.90s
โ””โ”€โ”€ node_modules/matches-selector/index.js                       1.09 KB     80ms
โ””โ”€โ”€ + 10 more assets

Indeed. ๐Ÿ˜Ÿ

Can't reproduce anymore

Was this page helpful?
0 / 5 - 0 ratings

Related issues

medhatdawoud picture medhatdawoud  ยท  3Comments

algebraic-brain picture algebraic-brain  ยท  3Comments

Niggler picture Niggler  ยท  3Comments

donaldallen picture donaldallen  ยท  3Comments

mnn picture mnn  ยท  3Comments