Parcel: Parcel 2: couldn't import mjs files

Created on 18 Aug 2019  ยท  3Comments  ยท  Source: parcel-bundler/parcel

๐Ÿ› bug report

I got a problem in [email protected] when I import a module which contain index.mjs and index.js. For example [email protected] - check my example

-> % npm start

> parcel2-example-bug@ start /Users/vladislav/dev/example-svelte3
> parcel build src/index.html --no-cache --no-minify

ร— External modules are not supported when building for browser
at Object.generateExternalImport (./node_modules/@parcel/scope-hoisting/lib/formats/global.js:37:9)
at exit (./node_modules/@parcel/scope-hoisting/lib/link.js:540:23)
at NodePath._call (./node_modules/@babel/traverse/lib/path/context.js:53:20)
at NodePath.call (./node_modules/@babel/traverse/lib/path/context.js:40:17)
at NodePath.visit (./node_modules/@babel/traverse/lib/path/context.js:97:8)
at TraversalContext.visitQueue (./node_modules/@babel/traverse/lib/context.js:118:16)
at TraversalContext.visitSingle (./node_modules/@babel/traverse/lib/context.js:90:19)
at TraversalContext.visit (./node_modules/@babel/traverse/lib/context.js:146:19)
at Function.traverse.node (./node_modules/@babel/traverse/lib/index.js:94:17)
at traverse (./node_modules/@babel/traverse/lib/index.js:76:12)

When I manualy remove index.mjs from svelte it works fine

Bug Confirmed Bug โœจ Parcel 2

Most helpful comment

I updated the issue and the example with fresh Parcel version.

All 3 comments

I think this is rather related to the sub packages inside of svelte:

node_modules/svelte/
โ”œโ”€โ”€ internal
โ”‚ย ย  โ”œโ”€โ”€ index.mjs
โ”‚ย ย  โ””โ”€โ”€ package.json
โ”œโ”€โ”€ package.json
โ””โ”€โ”€ store
    โ”œโ”€โ”€ index.mjs
    โ””โ”€โ”€ package.json

I updated the issue and the example with fresh Parcel version.

The main/module/browser fields in package.json turn on library mode: node modules aren't bundled (as you would expect for a library...). It tried that in this case as well. But having imports to bare specifiers on a webpage wouldn't work, therefore the error.

To fix this:

diff --git package.json package.json
index 7570c2c..385ad5b 100644
--- package.json
+++ package.json
@@ -1,6 +1,5 @@
 {
   "name": "parcel2-example-bug",
-  "browser": "dist/index.html",
   "source": "src/index.html",
   "private": true,
   "scripts": {
Was this page helpful?
0 / 5 - 0 ratings

Related issues

algebraic-brain picture algebraic-brain  ยท  3Comments

medhatdawoud picture medhatdawoud  ยท  3Comments

jzimmek picture jzimmek  ยท  3Comments

donaldallen picture donaldallen  ยท  3Comments

adamreisnz picture adamreisnz  ยท  3Comments