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

Build fails with Cannot read properties of undefined (reading 'substring') #873

Closed
3 tasks done
joseTeldoc opened this issue Jun 27, 2022 · 3 comments
Closed
3 tasks done
Labels
question This is a question rather than an issue or pull request

Comments

@joseTeldoc
Copy link

Describe the bug

Although vitepress dev docs works perfectly, when I try to build for production, I get an error which I cannot trace.

What reasons could be preventing the build? Or at least, how could I at least inspect the .temp/app.js file to understand which line fails?

❯ yarn build:docs
yarn run v1.22.17
$ vitepress build docs
vitepress v1.0.0-alpha.4
/Users/joseporto/project/teldoc/shared/ui/docs/.vitepress
✓ building client + server bundles...
✖ rendering pages...
build error:
 TypeError: Cannot read properties of undefined (reading 'substring')
    at /Users/joseporto/project/shared/ui/docs/.vitepress/.temp/app.js:608:46
    at Array.forEach (<anonymous>)
    at Function.install (/Users/joseporto/project/teldoc/shared/ui/docs/.vitepress/.temp/app.js:607:20)
    at Object.use (/Users/joseporto/project/teldoc/shared/ui/node_modules/@vue/runtime-core/dist/runtime-core.cjs.prod.js:3393:28)
    at Object.enhanceApp (/Users/joseporto/project/teldoc/shared/ui/docs/.vitepress/.temp/app.js:634:9)
    at createApp (/Users/joseporto/project/teldoc/shared/ui/docs/.vitepress/.temp/app.js:822:11)
    at renderPage (file:///Users/joseporto/project/teldoc/shared/ui/node_modules/vitepress/dist/node/serve-05342c3d.js:39535:27)
    at async build (file:///Users/joseporto/project/teldoc/shared/ui/node_modules/vitepress/dist/node/serve-05342c3d.js:39853:9)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Reproduction

Not reproducible since it's only happening with this project.

Expected behavior

Vitepress builds or at least outputs a more meaningful error message.

System Info

System:
    OS: macOS 12.4
    CPU: (8) arm64 Apple M1
    Memory: 80.83 MB / 16.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 17.9.1 - ~/.nvm/versions/node/v17.9.1/bin/node
    Yarn: 1.22.17 - /opt/homebrew/bin/yarn
    npm: 8.11.0 - ~/.nvm/versions/node/v17.9.1/bin/npm
  Browsers:
    Chrome: 103.0.5060.53
    Safari: 15.5
  npmPackages:
    vitepress: ^1.0.0-alpha.4 => 1.0.0-alpha.4

Additional context

No response

Validations

  • Follow our Code of Conduct
  • Read the docs.
  • Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
@joseTeldoc joseTeldoc added the bug: pending triage Maybe a bug, waiting for confirmation label Jun 27, 2022
@brc-dd
Copy link
Member

brc-dd commented Jun 27, 2022

Or at least, how could I at least inspect the .temp/app.js file to understand which line fails?

This will be added in the next release (track #856). You can then set DEBUG environment variable to prevent deleting .temp.

Also, if I've to guess with the error output only, I'll start with any libraries you might have added using enhanceApp in vitepress config.

@brc-dd brc-dd added question This is a question rather than an issue or pull request and removed bug: pending triage Maybe a bug, waiting for confirmation labels Jun 27, 2022
@joseTeldoc
Copy link
Author

thanks @brc-dd, it was indeed one of the libs added in enhanceApp. Ultimately it had to do with the fact that in production you cannot extract component.name but component.__name instead. Really hard to track this one.

For future reference, and considering vitepress: ^1.0.0-alpha.4 => 1.0.0-alpha.4

I ended up just removing the await lib$1.remove(siteConfig.tempDir) in vitepress npm module, to bypass the temp file deletion. This immediately allowed me to find the offending line.

@postmodernistx
Copy link
Contributor

For what it's worth, I had my Vue component template script like so:

<script>
export default {
  //
  methods: {
    doSomething() { /**/ },
  },
}
</script>
<template>
  <td v-for="d in 7">
    <div v-html="this.doSomething(d + 1)"></div>
  </td>
</template>

And when building, got the following error: TypeError: Cannot read properties of undefined (reading 'doSomething').

Removing this from the v-html directive fixed the issue:

<td v-for="d in 7">
  <div v-html="doSomething(d + 1)"></div>
</td>

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
question This is a question rather than an issue or pull request
Projects
None yet
Development

No branches or pull requests

3 participants