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

TypeError: Cannot read properties of undefined (reading 'config') with 6.0.7 #19144

Closed
7 tasks done
Artur- opened this issue Jan 6, 2025 · 4 comments
Closed
7 tasks done

Comments

@Artur-
Copy link
Contributor

Artur- commented Jan 6, 2025

Describe the bug

Running vite build with Vite 6.0.7 fails with

error during build:
TypeError: Cannot read properties of undefined (reading 'config')
    at Object.renderChunk (file:///.../flow-tests/test-express-build/test-dev-bundle/node_modules/vite/dist/node/chunks/dep-BJP6rrE_.js:12289:39)
    at file:///.../flow-tests/test-express-build/test-dev-bundle/node_modules/rollup/dist/es/shared/node-entry.js:20812:40

the referenced line is

const buildEsbuildPlugin = () => {
  return {
    name: "vite:esbuild-transpile",
    applyToEnvironment(environment) {
      return environment.config.esbuild !== false;
    },
    async renderChunk(code, chunk, opts) {
      if (opts.__vite_skip_esbuild__) {
        return null;
      }
      const config = this.environment.config; // This one

The code was added in #19025

Reproduction

vaadin/flow#20799

Steps to reproduce

mvn clean install -DskipTests

System Info

System:
    OS: macOS 15.2
    CPU: (10) arm64 Apple M1 Max
    Memory: 99.42 MB / 64.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 22.12.0 - ~/.nvm/versions/node/v22.12.0/bin/node
    npm: 10.9.0 - ~/.nvm/versions/node/v22.12.0/bin/npm
    bun: 1.0.7 - ~/.bun/bin/bun
  Browsers:
    Brave Browser: 107.1.45.123
    Chrome: 131.0.6778.205
    Chrome Canary: 133.0.6940.0
    Edge: 131.0.2903.112
    Safari: 18.2
    Safari Technology Preview: 18.2
  npmPackages:
    @vitejs/plugin-react: 4.3.4 => 4.3.4 
    vite: 6.0.7 => 6.0.7

Used Package Manager

npm

Logs

No response

Validations

Copy link

github-actions bot commented Jan 7, 2025

Hello @Artur-. Please provide a minimal reproduction using a GitHub repository or StackBlitz. Issues marked with needs reproduction will be closed if they have no activity within 3 days.

@hi-ogawa
Copy link
Collaborator

hi-ogawa commented Jan 7, 2025

Can you try minimizing a repro? I cannot even tell which vite config or plugins are used.

@Artur-
Copy link
Contributor Author

Artur- commented Jan 7, 2025

Thanks for having a look, I dug a bit deeper to see what is going on and now I am not sure if this is a Vite issue or not even though it has worked for a long time. The problem seems to come from this code, which runs rollup inside the Vite config:
https://github.com/vaadin/flow/blob/e365417d6cf0c15ebfe8aaba14073976eb31f220/flow-server/src/main/resources/vite.generated.ts#L156-L171

@hi-ogawa
Copy link
Collaborator

hi-ogawa commented Jan 7, 2025

It looks like you're reusing Vite (internal) plugin as rollup plugin https://github.com/vaadin/flow/blob/e365417d6cf0c15ebfe8aaba14073976eb31f220/flow-server/src/main/resources/vite.generated.ts#L127-L135 and technically that's not supported officially. The change made by #19025 is a legitimate fix for Vite's own usage (and similar changes have been done / will be done for other internal plugins as well), so I think you have to find an alternative for doing sub build from your plugin.

Though not knowing much context, how about using Vite's build API instead of rollup?

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

No branches or pull requests

2 participants