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

Reusing variable names between module scripts in entry html causes devServer to fail #6851

Closed
7 tasks done
OliverTsang opened this issue Feb 10, 2022 · 1 comment · Fixed by #6818
Closed
7 tasks done
Labels
p3-minor-bug An edge case that only affects very specific usage (priority) pending triage

Comments

@OliverTsang
Copy link
Contributor

OliverTsang commented Feb 10, 2022

Describe the bug

I have an entry html (such as index.html) like this:

<script type="module">
  const el = document.createElement('span');
  el.innerHTML = 'hello ';
  document.body.appendChild(el);
</script>

<script type="module">
  const el = document.createElement('span');
  el.innerHTML = 'world';
  document.body.appendChild(el);
</script>

I reused variable names between different module scripts, and then i ran vite and got an error:

The symbol "el" has already been declared

This error will cause the devServer to fail to start. The current workaround is to not reuse variable names between html module scripts.

I think this is a bug, because if you access an html directly in the browser, you can use the same variable name in different module scripts.

Reproduction

https://stackblitz.com/edit/vitejs-vite-kabw2t?file=package.json&terminal=dev

System Info

System:
    OS: macOS 10.15.5
    CPU: (8) x64 Intel(R) Core(TM) i7-8557U CPU @ 1.70GHz
    Memory: 201.05 MB / 16.00 GB
    Shell: 5.7.1 - /bin/zsh
  Binaries:
    Node: 14.4.0 - /usr/local/bin/node
    Yarn: 1.22.17 - /usr/local/bin/yarn
    npm: 6.14.4 - /usr/local/bin/npm
  Browsers:
    Chrome: 98.0.4758.80
    Safari: 13.1.1
  npmPackages:
    vite: ^2.7.2 => 2.8.0

Used Package Manager

npm

Logs

✘ [ERROR] The symbol "el" has already been declared

    html:/home/projects/vitejs-vite-kabw2t/index.html:8:12:
      8 │       const el = document.createElement('span');~~

  The symbol "el" was originally declared here:

    html:/home/projects/vitejs-vite-kabw2t/index.html:3:12:
      3 │       const el = document.createElement('span');~~

  vite:resolve 0.80ms /main.js -> /home/projects/vitejs-vite-kabw2t/main.js +0ms
error when starting dev server:
Error: Build failed with 1 error:
html:/home/projects/vitejs-vite-kabw2t/index.html:8:12: ERROR: The symbol "el" has already been declared
    at failureErrorWithLog (/home/projects/vitejs-vite-kabw2t/node_modules/esbuild/lib/main.js:1557:15)
    at eval (/home/projects/vitejs-vite-kabw2t/node_modules/esbuild/lib/main.js:1215:28)
    at runOnEndCallbacks (/home/projects/vitejs-vite-kabw2t/node_modules/esbuild/lib/main.js:1005:63)
    at buildResponseToResult (/home/projects/vitejs-vite-kabw2t/node_modules/esbuild/lib/main.js:1213:7)
    at eval (/home/projects/vitejs-vite-kabw2t/node_modules/esbuild/lib/main.js:1322:14)
    at eval (/home/projects/vitejs-vite-kabw2t/node_modules/esbuild/lib/main.js:637:9)
    at handleIncomingPacket (/home/projects/vitejs-vite-kabw2t/node_modules/esbuild/lib/main.js:734:9)
    at Socket.readFromStdout (/home/projects/vitejs-vite-kabw2t/node_modules/esbuild/lib/main.js:604:7)
    at Socket.EventEmitter.emit (https://vitejs-vite-kabw2t.w.staticblitz.com/blitz.05388ae171e3a0a12539f1efbda0fa1189d4f549.js:6:130023)
    at addChunk (https://vitejs-vite-kabw2t.w.staticblitz.com/blitz.05388ae171e3a0a12539f1efbda0fa1189d4f549.js:6:526052)

Validations

@OliverTsang
Copy link
Contributor Author

OliverTsang commented Feb 10, 2022

I try to fix it in #6818, I hope this PR will help with this issue. Thx!

@bluwy bluwy added the p3-minor-bug An edge case that only affects very specific usage (priority) label Feb 14, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Mar 19, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
p3-minor-bug An edge case that only affects very specific usage (priority) pending triage
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants