Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Error: Got unexpected undefined" from parcel serve when errors present in Vue (SFC?) code #7395

Closed
mjog opened this issue Dec 2, 2021 · 3 comments

Comments

@mjog
Copy link

mjog commented Dec 2, 2021

🐛 bug report

When starting parcel serve src/index.html for a project I just upgraded from Parcel 1, I now get the following error whenever a build error is present:

Building...
🚨 Build failed.
Error: Got unexpected undefined
    at nullthrows (/home/mjog/Projects/vee.net/planetary/node_modules/.pnpm/nullthrows@1.1.1/node_modules/nullthrows/nullthrows.js:7:15)
    at prettyDiagnostic (/home/mjog/Projects/vee.net/planetary/node_modules/.pnpm/@parcel+utils@2.0.1/node_modules/@parcel/utils/lib/prettyDiagnostic.js:100:181)
    at writeDiagnostic (/home/mjog/Projects/vee.net/planetary/node_modules/.pnpm/@parcel+reporter-cli@2.0.1_@parcel+core@2.0.1/node_modules/@parcel/reporter-cli/lib/CLIReporter.js:207:45)
    at _report (/home/mjog/Projects/vee.net/planetary/node_modules/.pnpm/@parcel+reporter-cli@2.0.1_@parcel+core@2.0.1/node_modules/@parcel/reporter-cli/lib/CLIReporter.js:151:13)
    at Object.report (/home/mjog/Projects/vee.net/planetary/node_modules/.pnpm/@parcel+reporter-cli@2.0.1_@parcel+core@2.0.1/node_modules/@parcel/reporter-cli/lib/CLIReporter.js:265:12)
    at ReporterRunner.report (/home/mjog/Projects/vee.net/planetary/node_modules/.pnpm/@parcel+core@2.0.1/node_modules/@parcel/core/lib/ReporterRunner.js:105:33)
    at Parcel._build (/home/mjog/Projects/vee.net/planetary/node_modules/.pnpm/@parcel+core@2.0.1/node_modules/@parcel/core/lib/Parcel.js:464:34) {
  framesToPop: 1
}
Error: Got unexpected undefined
    at nullthrows (/home/mjog/Projects/vee.net/planetary/node_modules/.pnpm/nullthrows@1.1.1/node_modules/nullthrows/nullthrows.js:7:15)
    at prettyDiagnostic (/home/mjog/Projects/vee.net/planetary/node_modules/.pnpm/@parcel+utils@2.0.1/node_modules/@parcel/utils/lib/prettyDiagnostic.js:100:181)
    at /home/mjog/Projects/vee.net/planetary/node_modules/.pnpm/@parcel+reporter-dev-server@2.0.1_@parcel+core@2.0.1/node_modules/@parcel/reporter-dev-server/lib/Server.js:160:64
    at Array.map (<anonymous>)
    at Server.buildError (/home/mjog/Projects/vee.net/planetary/node_modules/.pnpm/@parcel+reporter-dev-server@2.0.1_@parcel+core@2.0.1/node_modules/@parcel/reporter-dev-server/lib/Server.js:157:49)
    at Object.report (/home/mjog/Projects/vee.net/planetary/node_modules/.pnpm/@parcel+reporter-dev-server@2.0.1_@parcel+core@2.0.1/node_modules/@parcel/reporter-dev-server/lib/ServerReporter.js:144:24)
    at ReporterRunner.report (/home/mjog/Projects/vee.net/planetary/node_modules/.pnpm/@parcel+core@2.0.1/node_modules/@parcel/core/lib/ReporterRunner.js:105:33) {
  framesToPop: 1
}

Adding some debug statements, I managed to work out that the underlying error is in some Vue code, and that the compiler doesn't seem to passing in a file path as part of the diagnostic object argument when calling prettyDiagnostic() - the second to last function in the stack above. As a result the filePath variable in that function is null in the stack above.

I can work around this by changing prettyDiagnostics()'s implementation from:

      …

      let highlights = codeFrame.codeHighlights;
      let code = (_codeFrame$code = codeFrame.code) !== null && _codeFrame$code !== void 0 ? _codeFrame$code : options && (await options.inputFS.readFile((0, _nullthrows().default)(filePath), 'utf8'));
      let formattedCodeFrame = '';

      if (code != null) {
      …

to:

      …
      let highlights = codeFrame.codeHighlights;
      let code = null;

      if ((_codeFrame$code = codeFrame.code) !== null && _codeFrame$code !== void 0) {
        code = _codeFrame$code;
      } else if (filePath != null && options) {
        code = await options.inputFS.readFile(filePath, 'utf8');
      }

      let formattedCodeFrame = '';
      if (code != null) {
      …

(Apologies for the crap patch, but I don't have the headspace to get a PR together for this at the moment.)

In doing so I get a slightly more helpful error message:

Server running at https://localhost:1234
🚨 Build failed.

@parcel/transformer-vue: <Transition> expects exactly one child element or component.

  SyntaxError: <Transition> expects exactly one child element or component.
  at Object.createCompilerError
  (/home/mjog/Projects/vee.net/planetary/node_modules/.pnpm/@vue+compiler-core@3.2.23/node_modules/@vue/compiler-core/dist/compiler-core.cjs.js:19:19)
  at createDOMCompilerError
  (/home/mjog/Projects/vee.net/planetary/node_modules/.pnpm/@vue+compiler-dom@3.2.23/node_modules/@vue/compiler-dom/dist/compiler-dom.cjs.js:2483:25)
  at Array.<anonymous>
  (/home/mjog/Projects/vee.net/planetary/node_modules/.pnpm/@vue+compiler-dom@3.2.23/node_modules/@vue/compiler-dom/dist/compiler-dom.cjs.js:2746:37)
  at traverseNode
  (/home/mjog/Projects/vee.net/planetary/node_modules/.pnpm/@vue+compiler-core@3.2.23/node_modules/@vue/compiler-core/dist/compiler-core.cjs.js:2223:19)
  at traverseChildren
  (/home/mjog/Projects/vee.net/planetary/node_modules/.pnpm/@vue+compiler-core@3.2.23/node_modules/@vue/compiler-core/dist/compiler-core.cjs.js:2165:9)
  at traverseNode
  (/home/mjog/Projects/vee.net/planetary/node_modules/.pnpm/@vue+compiler-core@3.2.23/node_modules/@vue/compiler-core/dist/compiler-core.cjs.js:2216:13)
  at traverseChildren
  (/home/mjog/Projects/vee.net/planetary/node_modules/.pnpm/@vue+compiler-core@3.2.23/node_modules/@vue/compiler-core/dist/compiler-core.cjs.js:2165:9)
  at traverseNode
  (/home/mjog/Projects/vee.net/planetary/node_modules/.pnpm/@vue+compiler-core@3.2.23/node_modules/@vue/compiler-core/dist/compiler-core.cjs.js:2216:13)
  at traverseChildren
  (/home/mjog/Projects/vee.net/planetary/node_modules/.pnpm/@vue+compiler-core@3.2.23/node_modules/@vue/compiler-core/dist/compiler-core.cjs.js:2165:9)
  at traverseNode
  (/home/mjog/Projects/vee.net/planetary/node_modules/.pnpm/@vue+compiler-core@3.2.23/node_modules/@vue/compiler-core/dist/compiler-core.cjs.js:2216:13)

So while this bug is obstinately covering the issue that no decent error is reported when filePath is null, it would also be good to get the Vue compiler to report the path correctly as well. I suspect this is an issue with Vue SFC, since aside from the bootstrapping, all view code is in SVCs in this project - indeed that bogus use of <transition> certainly is in a SFC.

@photocurio
Copy link

Thank you for finding this! I've been going zombie-eyed while getting Got unexpected undefined at nullthrows all week. Your patch told me where the error was. OK, my error was also <Transition> expects exactly one child element or component.

Anyway please put in a pull request!

@github-actions
Copy link

github-actions bot commented Jul 7, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs.

@github-actions github-actions bot added the Stale Inactive issues label Jul 7, 2022
@lol768
Copy link
Contributor

lol768 commented Sep 23, 2022

This is the problem with these "let's automatically close stale issues" bots.

The patch still hasn't been applied to prettyDiagnostics. The latest stable version still gives me these opaque errors:

Error: Got unexpected undefined
    at $812806c6461f2963$var$nullthrows (/home/adam/Documents/project/node_modules/@parcel/utils/lib/index.js:3485:17)
    at $f02d6a9d30f55938$export$2e2bcd8739ae039 (/home/adam/Documents/project/node_modules/@parcel/utils/lib/index.js:32342:195)
    at $7c213f7c22b64117$var$writeDiagnostic (/home/adam/Documents/project/node_modules/@parcel/reporter-cli/lib/CLIReporter.js:7435:167)
    at $7c213f7c22b64117$export$12358408d9820617 (/home/adam/Documents/project/node_modules/@parcel/reporter-cli/lib/CLIReporter.js:7401:19)

I'm having to manually patch the JS in line with @mjog's issue description to get anything useful out of Parcel here. Why can't we keep this issue open until it gets fixed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants