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 failed: Unterminated string literal #11966

Closed
thril opened this issue Feb 7, 2023 · 3 comments
Closed

Build failed: Unterminated string literal #11966

thril opened this issue Feb 7, 2023 · 3 comments
Labels
enhancement New feature or request feat: html

Comments

@thril
Copy link

thril commented Feb 7, 2023

Describe the bug

When I include a dynamic entry point into my app and start the dev server, I get an error that the build failed.

// vite.config.js
import { defineConfig } from 'vite';
import { createHtmlPlugin } from 'vite-plugin-html';

export default defineConfig(() => {
  return {
    plugins: [
      // @see https://github.com/vbenjs/vite-plugin-html#usage
      createHtmlPlugin({
        inject: {
          data: {
            ENTRY_POINT: '/main.js',
          },
        },
      }),
    ],
  };
});

In the index.html file, I dynamically set the entry point using the format...

<script type="module" src="<%- ENTRY_POINT %>"></script>

When I start the vite dev server, I get...

$ vite
                                                                                                  08:44:49
  VITE v4.1.1  ready in 1658 ms

  ➜  Local:   http://localhost:5173/                                                              08:44:49
  ➜  Network: use --host to expose                                                                08:44:49
  ➜  press h to show help                                                                         08:44:49
✘ [ERROR] Unterminated string literal

    script:/home/projects/vitejs-vite-bdubvy/index.html?id=0:1:2:
      1 │ ">
        ╵   ^

 ERROR  Build failed with 1 error:                                                                08:44:49
script:/home/projects/vitejs-vite-bdubvy/index.html?id=0:1:2: ERROR: Unterminated string literal

Even though this error occurs, the app starts just fine.

Reproduction

https://stackblitz.com/edit/vitejs-vite-bdubvy?file=vite.config.js

Steps to reproduce

Run npm install followed by npm run dev

System Info

🍕 npx envinfo --system --npmPackages '{vite,@vitejs/*}' --binaries --browsers

  System:
    OS: macOS 13.1
    CPU: (8) arm64 Apple M1
    Memory: 87.66 MB / 16.00 GB
    Shell: 5.1.16 - /opt/homebrew/bin/bash
  Binaries:
    Node: 16.19.0 - ~/.nvm/versions/node/v16.19.0/bin/node
    Yarn: 1.22.19 - /opt/homebrew/bin/yarn
    npm: 8.5.5 - /opt/homebrew/bin/npm
    Watchman: 2022.10.24.00 - /opt/homebrew/bin/watchman
  Browsers:
    Chrome: 109.0.5414.119
    Firefox: 109.0.1
    Safari: 16.2
  npmPackages:
    @vitejs/plugin-basic-ssl: ^1.0.1 => 1.0.1 
    @vitejs/plugin-react: ^3.1.0 => 3.1.0 
    vite: ^4.1.1 => 4.1.1 


### Used Package Manager

yarn

### Logs

_No response_

### Validations

- [X] Follow our [Code of Conduct](https://github.com/vitejs/vite/blob/main/CODE_OF_CONDUCT.md)
- [X] Read the [Contributing Guidelines](https://github.com/vitejs/vite/blob/main/CONTRIBUTING.md).
- [X] Read the [docs](https://vitejs.dev/guide).
- [X] Check that there isn't [already an issue](https://github.com/vitejs/vite/issues) that reports the same bug to avoid creating a duplicate.
- [X] Make sure this is a Vite issue and not a framework-specific issue. For example, if it's a Vue SFC related bug, it should likely be reported to [vuejs/core](https://github.com/vuejs/core) instead.
- [X] Check that this is a concrete bug. For Q&A open a [GitHub Discussion](https://github.com/vitejs/vite/discussions) or join our [Discord Chat Server](https://chat.vitejs.dev/).
- [X] The provided reproduction is a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example) of the bug.
@fi3ework
Copy link
Member

fi3ework commented Feb 7, 2023

duplicate with vbenjs/vite-plugin-html#9

@bluwy
Copy link
Member

bluwy commented Feb 19, 2023

Maybe the fix here is to run transformIndexHtml when scanning. That way we can detected injected scripts and crawl them too.

@bluwy bluwy added enhancement New feature or request feat: html and removed pending triage labels Feb 19, 2023
@bluwy
Copy link
Member

bluwy commented Nov 12, 2023

In retrospect, I think it's unlikely that we'll run transformIndexHtml when scanning as it'll slow down the startup. And we haven't got similar reports of this being an issue. I'll go ahead and close this as a wontfix for now.

@bluwy bluwy closed this as not planned Won't fix, can't repro, duplicate, stale Nov 12, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Nov 27, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request feat: html
Projects
None yet
Development

No branches or pull requests

3 participants