parcel v2 - Error: Got unexpected undefined

Created on 24 Jan 2020  ยท  8Comments  ยท  Source: parcel-bundler/parcel

๐Ÿ› bug report

While testing out parcel v2 I ran into a fatal build error with an internal-looking failure.

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

CLI
parcel watch ./src/ui/index.html

package.json

{
  "targets": {
    "browser": {"publicUrl": "/app"}
  }
}

babelrc

module.exports = {
  presets: ['@babel/preset-env'],
  plugins: [['@babel/plugin-transform-react-jsx', {pragma: 'h'}]],
};

๐Ÿค” Expected Behavior

It builds the project or provides an error message as to what is wrong with my configuration.

๐Ÿ˜ฏ Current Behavior

It fails with an internal undefined error message.

Error: Got unexpected undefined
    at nullthrows (/Users/patrick/Code/OpenSource/lighthouse-ci/node_modules/nullthrows/nullthrows.js:7:15)
    at RequestGraph.removeById (/Users/patrick/Code/OpenSource/lighthouse-ci/node_modules/@parcel/core/lib/Graph.js:188:40)
    at RequestTracker.untrackRequest (/Users/patrick/Code/OpenSource/lighthouse-ci/node_modules/@parcel/core/lib/RequestTracker.js:284:16)
    at AssetGraphBuilder.handleNodeRemovedFromAssetGraph (/Users/patrick/Code/OpenSource/lighthouse-ci/node_modules/@parcel/core/lib/AssetGraphBuilder.js:279:27)
    at AssetGraph.onNodeRemoved (/Users/patrick/Code/OpenSource/lighthouse-ci/node_modules/@parcel/core/lib/AssetGraphBuilder.js:107:35)
    at AssetGraph.removeNode (/Users/patrick/Code/OpenSource/lighthouse-ci/node_modules/@parcel/core/lib/AssetGraph.js:138:32)
    at AssetGraph.removeEdge (/Users/patrick/Code/OpenSource/lighthouse-ci/node_modules/@parcel/core/lib/Graph.js:215:12)
    at AssetGraph.removeNode (/Users/patrick/Code/OpenSource/lighthouse-ci/node_modules/@parcel/core/lib/Graph.js:179:14)
    at AssetGraph.removeNode (/Users/patrick/Code/OpenSource/lighthouse-ci/node_modules/@parcel/core/lib/AssetGraph.js:139:18)
    at AssetGraph.removeEdge (/Users/patrick/Code/OpenSource/lighthouse-ci/node_modules/@parcel/core/lib/Graph.js:215:12)

๐Ÿ”ฆ Context

Trying to help test out parcel v2 :)

๐Ÿ’ป Code Sample

https://github.com/GoogleChrome/lighthouse-ci/tree/parcelv2/packages/server

in repo root, run yarn and then yarn build:watch

๐ŸŒ Your Environment

| Software | Version(s) |
| ---------------- | ---------- |
| Parcel | 2.0.0-alpha.3.2 |
| Node | v10.15.3 |
| npm/Yarn |
| Operating System | macOS |

Question โœจ Parcel 2

Most helpful comment

I think it was because of the cache, after clearing the cache it builds but now I get this error: This experimental syntax requires enabling the parser plugin: 'classProperties'.

Related: https://github.com/parcel-bundler/parcel/issues/2668 , but the fix mentioned there doesn't work.

All 8 comments

This is already fixed with the version on master. However, here are some changed that were needed:

  • use babel.config.json instead of babel.config.js for better caching (added in Babel 7.7.0)
  • change the server's package.json because:

    • running parcel on a html entrypoint with main: "....js" fails because Parcel tries to emit a library version to that path (but that is not possible with an html file) - this change fixes the error you get. The next version will say here:

      Bildschirmfoto 2020-01-24 um 23 31 13

  • don#t use browser in targets because, again, this target name has a special meaning (a library for the browser)
    So with this, parcel@next works (though this might cause problems with server.js):
diff --git packages/server/package.json packages/server/package.json
index fd59922..a3bf460 100644
--- packages/server/package.json
+++ packages/server/package.json
@@ -1,6 +1,5 @@
 {
   "name": "@lhci/server",
-  "main": "./src/server.js",
   "version": "0.1.0",
   "license": "Apache-2.0",
   "repository": {
@@ -35,8 +34,9 @@
     "preact-async-route": "^2.2.1",
     "preact-router": "^3.1.0"
   },
+  "app": "dist/index.html",
   "targets": {
-    "browser": {
+    "app": {
       "publicUrl": "/app"
     }
   },

Thanks very much for the quick response!

running parcel on a html entrypoint with main: "....js" fails because Parcel tries to emit a library version to that path

Hm, is there a way around this? We have a legitimate main export for other libraries to require('@lhci/server') and start an express server, so we can't eliminate it. Parcel is just used to bundle the frontend assets before publishing which are then used by the regular commonjs code that is not processed by parcel.

I was afraid you were gonna ask that...

Currently not, though I might look into that tomorrow

I still get this error when I try building: Error: Got unexpected undefined.
I tried removing "main": "index.js" from package.json, tried changing it to index.html, tried adding main: false to targets and other fixes mentioned here. I am just building a normal React+TypeScript app for the browser. Watch mode works, but build fails:

package.json (simplified):

{
 "main": "index.html",
  "targets": {
    "main": false,
    "browser": {
      "publicUrl": "./"
    }
  }

You want

{
 "app": "dist/index.html", // <-- arbitrary name, just not main,browser,module,types
  "targets": {
    "app": {
      "publicUrl": "./"
    }
  }
}

and then parcel build src/index.html.
And maybe delete your cache ๐Ÿ˜ฌ

In package.json should it be dist/index.html or src/index.html ? Is it the input index.html or output (built) index.html ? It makes less sense to have the output specified as main.

It just builds an index.html and copies the favicon.ico. The .js and .css files are missing and not included:

Bundling...
โˆš Built in 3.80s

dist\index.html                                                 599 B      5ms
โ””โ”€โ”€ src\index.html                                              914 B    535ms

dist\favicon.9d6209bd.ico                                       365 B      1ms
โ””โ”€โ”€ src\favicon.ico                                             365 B      8ms

dist\version-3.HASH_REF_66e4fe8cf849a3a8766f679024347abe.js      67 B      0ms
โ””โ”€โ”€ src\index.html                                               67 B    535ms

dist\version-3.HASH_REF_ee35b87c1a0bfc51e2679f10a7e5f643.css     32 B      0ms
โ””โ”€โ”€ src\index.html                                               32 B    535ms

If I change "app" to "app": "src/index.html", I get the Got unexpected undefined again.

I think it was because of the cache, after clearing the cache it builds but now I get this error: This experimental syntax requires enabling the parser plugin: 'classProperties'.

Related: https://github.com/parcel-bundler/parcel/issues/2668 , but the fix mentioned there doesn't work.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

algebraic-brain picture algebraic-brain  ยท  3Comments

mnn picture mnn  ยท  3Comments

urbanhop picture urbanhop  ยท  3Comments

dsky1990 picture dsky1990  ยท  3Comments

philipodev picture philipodev  ยท  3Comments