Parcel: Client-side only "Cannot find module" when using code splitting

Created on 20 Feb 2020  ยท  2Comments  ยท  Source: parcel-bundler/parcel

๐Ÿ› bug report

If you're using code splitting and then two different chunks attempt to reference the same static file (e.g. an image). One of the chunks will get a client-side runtime error when attempting to require that static file Cannot find module './path/to/shared/static/file'.

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

Unconfigured, yarn add -D parcel@next && yarn parcel index.html, see example repo

๐Ÿค” Expected Behavior

No requires throw an error in either bundle

๐Ÿ˜ฏ Current Behavior

The require in both bundles throws an error.

๐Ÿ”ฆ Context

This has popped up a number of times in lighthouse-ci, but I finally found the minimal repro of it.

There's a nearly identical issue but it's claimed to be fixed in parcel 2 already, so perhaps this is slightly different?
https://github.com/parcel-bundler/parcel/issues/112 https://github.com/parcel-bundler/parcel/issues/112#issuecomment-562856846

Similarish issues that still seemed slightly different to me

https://github.com/parcel-bundler/parcel/issues/3442 (possibly?)
https://github.com/parcel-bundler/parcel/issues/2515 (unresolved and unsubstantiated, maybe some of those are related?)

๐Ÿ’ป Code Sample

entry.js

setTimeout(() => import('./module.a.js'), 1000)
setTimeout(() => import('./module.b.js'), 0)

module-a.js

console.log('A says', require('./logo.svg'))

module-b.js

import './module-a.js'
console.log('B says', require('./logo.svg'))

In this example B is importing A directly for simplicity but the same issue occurs if there is a shared file C.

See https://github.com/patrickhulce/parcel-bug-code-splitting

๐ŸŒ Your Environment

| Software | Version(s) |
| ---------------- | ---------- |
| Parcel | 1.12.4 and 2.0.0-alpha.3.2 both affected |
| Node | v10.15.3
| npm/Yarn | N/A
| Operating System | macOS |

Bug โœจ Parcel 2

Most helpful comment

Having the exact same issue in parcel 1.12.3, the description is spot-on. Is there any workaround for this at the moment, apart from _not_ using code-splitting .. ?

All 2 comments

Having the exact same issue in parcel 1.12.3, the description is spot-on. Is there any workaround for this at the moment, apart from _not_ using code-splitting .. ?

Codesplitting works for me, BUT only in build. The dev server page throws:

Cannot find module '../node_modules/parcel-bundler/src/builtins/bundle-url.js'
Was this page helpful?
0 / 5 - 0 ratings

Related issues

Niggler picture Niggler  ยท  3Comments

philipodev picture philipodev  ยท  3Comments

adamreisnz picture adamreisnz  ยท  3Comments

devongovett picture devongovett  ยท  3Comments

humphd picture humphd  ยท  3Comments