parcel-bundler / parcel

The zero configuration build tool for the web. 📦🚀
https://parceljs.org
MIT License
43.47k stars 2.27k forks source link

parcel v2 - Error: Got unexpected undefined #4035

Closed patrickhulce closed 4 years ago

patrickhulce commented 4 years ago

🐛 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
mischnic commented 4 years ago

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

patrickhulce commented 4 years ago

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.

mischnic commented 4 years ago

I was afraid you were gonna ask that...

Currently not, though I might look into that tomorrow

mischnic commented 4 years ago

-> https://github.com/parcel-bundler/parcel/pull/4036

Cristy94 commented 4 years ago

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": "./"
    }
  }
mischnic commented 4 years ago

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 😬

Cristy94 commented 4 years ago

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.

Cristy94 commented 4 years ago

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.

jayantbh commented 3 years ago

For me, cleaning the cache fixed the issue. 😅

photocurio commented 2 years ago

Dang it.. why am I getting this same problem a year after the issue was closed? I am using Parcel 2.0.1.

Parcel watch fails, with the undefined error. Parcel build completes.

Software Version(s)
Parcel 2.0.1
Node 14.17.6
npm 6.14.15
Operating System Mac OS 11.6.1

Parcel watch gives me this:

Error: Got unexpected undefined
at nullthrows (/Users/a3235181/projects/telehealth/telehealth-web-app/node_modules/nullthrows/nullthrows.js:7:15)
at prettyDiagnostic (/Users/a3235181/projects/telehealth/telehealth-web-app/node_modules/@parcel/utils/lib/prettyDiagnostic.js:100:181)
at writeDiagnostic (/Users/a3235181/projects/telehealth/telehealth-web-app/node_modules/@parcel/reporter-cli/lib/CLIReporter.js:207:45)
at _report (/Users/a3235181/projects/telehealth/telehealth-web-app/node_modules/@parcel/reporter-cli/lib/CLIReporter.js:151:13)
at Object.report (/Users/a3235181/projects/telehealth/telehealth-web-app/node_modules/@parcel/reporter-cli/lib/CLIReporter.js:265:12)
at ReporterRunner.report (/Users/a3235181/projects/telehealth/telehealth-web-app/node_modules/@parcel/core/lib/ReporterRunner.js:105:33)
at Parcel._build (/Users/a3235181/projects/telehealth/telehealth-web-app/node_modules/@parcel/core/lib/Parcel.js:464:34)
at async Parcel._startNextBuild (/Users/a3235181/projects/telehealth/telehealth-web-app/node_modules/@parcel/core/lib/Parcel.js:298:24)
at async PromiseQueue._runFn (/Users/a3235181/projects/telehealth/telehealth-web-app/node_modules/@parcel/utils/lib/PromiseQueue.js:88:7)
at async PromiseQueue._next (/Users/a3235181/projects/telehealth/telehealth-web-app/node_modules/@parcel/utils/lib/PromiseQueue.js:75:5)

My package json is this:

{
    "name": "patienthub-telehealth",
    "app": "dist/index.html",
    "targets": {
        "app": {
            "publicUrl": "/"
        }
    },
    "scripts": {
        "build-watch": "parcel watch client/index.html",
        "start-watch": "nodemon server/index.js",
        "dev": "concurrently --kill-others \"npm run start-watch\" \"npm run build-watch\"",
        "build": "parcel build client/index.html --no-source-maps",
        "start": "npm run build && node server/index.js"
    },
    "author": "Peter Mumford",
    "license": "MIT",
    "devDependencies": {
        "@babel/core": "^7.15.8",
        "@babel/plugin-transform-runtime": "^7.15.8",
        "@babel/runtime-corejs2": "^7.15.4",
        "@parcel/transformer-sass": "^2.0.1",
        "@parcel/transformer-vue": "^2.0.1",
        "@vue/compiler-sfc": "^3.2.26",
        "@vue/component-compiler-utils": "^3.2.2",
        "concurrently": "^6.3.0",
        "parcel": "^2.0.1",
        "postcss": "^8.4.5"
    },
   "dependencies": {
        "@azure/communication-calling": "^1.3.2-beta.1",
        "@azure/communication-common": "^1.1.0",
        "@azure/communication-identity": "^1.0.0",
        "@azure/communication-signaling": "^1.0.0-beta.11",
        "@popperjs/core": "^2.10.2",
        "@progresskinvey/saml2js": "git+https://github.com/Kinvey/saml2js.git",
        "axios": "^0.24.0",
        "bootstrap": "^5.1.2",
        "cookie-parser": "^1.4.5",
        "detect-browser": "^5.2.1",
        "detect.js": "^2.2.3",
        "dotenv": "^10.0.0",
        "express": "^4.17.1",
        "express-async-errors": "^3.1.1",
        "express-session": "1.17.1",
        "img": "^3.0.3",
        "keyv": "^4.0.4",
        "network-speed": "^2.1.1",
        "passport": "0.4.1",
        "passport-saml": "1.3.3",
        "useragent": "^2.3.0",
        "vue": "^2.6.14",
        "winston": "^3.3.3"
    }
}
photocurio commented 2 years ago

Update. This helped me solve my problem: https://github.com/parcel-bundler/parcel/issues/7395

I had multiple root elements in a Transition element in a Vue file. Parcel 1 and Vue 2 did not object to this.

geeteshydv commented 6 months ago

Delete the parcel-cache folder. It worked for me thanks.