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)
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
โจ 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.
โจ 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");
Default to regular bundling for browsers, rather than generating a CommonJS file.
| 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
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 initadds 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.jsondefaults topackage.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.
Works as expected โจ
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