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

esbuild: Unterminated string literal when building SSR bundle #3985

Closed
murl-digital opened this issue Feb 17, 2022 · 7 comments
Closed

esbuild: Unterminated string literal when building SSR bundle #3985

murl-digital opened this issue Feb 17, 2022 · 7 comments
Labels
bug Something isn't working p3-edge-case SvelteKit cannot be used in an uncommon way vite
Milestone

Comments

@murl-digital
Copy link

murl-digital commented Feb 17, 2022

Describe the bug

This is an issue that first appeared for me 2 days ago, where all builds would fail because of a seemingly incomplete import statement in one specific file, where no such import statement existed. This could be fixed by deleting the file, starting the devserver, then adding the file back in while it's running. This workaround, however as far as I know, is not practical when deploying to Vercel in this case, as it would probably take a script to run the dev server with the file deleted, then subsequently readding it.

To the best of my knowledge, this does not have anything to do with vite, since I was unable to reproduce it with the SSR projects provided.

Reproduction

A copy of the project is on https://github.com/murl-digital/draconium.productions-mirror, and the problem has to do with /src/routes/index.svelte.

Logs

vite v2.8.3 building SSR bundle for production...
✘ [ERROR] Unterminated string literal
    html:/vercel/path0/src/routes/index.svelte:21:8:
      21 │ import "
         ╵         ^
> Build failed with 1 error:
html:/vercel/path0/src/routes/index.svelte:21:8: ERROR: Unterminated string literal
html:/vercel/path0/src/routes/index.svelte:21:8: ERROR: Unterminated string literal
    at failureErrorWithLog (/vercel/path0/node_modules/.pnpm/esbuild@0.14.22/node_modules/esbuild/lib/main.js:1602:15)
    at /vercel/path0/node_modules/.pnpm/esbuild@0.14.22/node_modules/esbuild/lib/main.js:1248:28
    at runOnEndCallbacks (/vercel/path0/node_modules/.pnpm/esbuild@0.14.22/node_modules/esbuild/lib/main.js:1033:63)
    at buildResponseToResult (/vercel/path0/node_modules/.pnpm/esbuild@0.14.22/node_modules/esbuild/lib/main.js:1246:7)
    at /vercel/path0/node_modules/.pnpm/esbuild@0.14.22/node_modules/esbuild/lib/main.js:1355:14
    at /vercel/path0/node_modules/.pnpm/esbuild@0.14.22/node_modules/esbuild/lib/main.js:665:9
    at handleIncomingPacket (/vercel/path0/node_modules/.pnpm/esbuild@0.14.22/node_modules/esbuild/lib/main.js:762:9)
    at Socket.readFromStdout (/vercel/path0/node_modules/.pnpm/esbuild@0.14.22/node_modules/esbuild/lib/main.js:632:7)
    at Socket.emit (events.js:400:28)
    at addChunk (internal/streams/readable.js:293:12)

System Info

Unable to run on Vercel, but here's my local machine where I also encountered this bug on.

System:
    OS: Windows 10 10.0.22000
    CPU: (16) x64 AMD Ryzen 7 3700X 8-Core Processor
    Memory: 38.76 GB / 63.92 GB
  Binaries:
    Node: 17.4.0 - C:\Program Files\nodejs\node.EXE
    npm: 8.3.0 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Edge: Spartan (44.22000.120.0), Chromium (98.0.1108.55)
    Internet Explorer: 11.0.22000.120
  npmPackages:
    @sveltejs/adapter-vercel: next => 1.0.0-next.43
    @sveltejs/kit: next => 1.0.0-next.278
    svelte: ^3.46.4 => 3.46.4
    vite: ^2.8.3 => 2.8.3

Severity

blocking all usage of SvelteKit

Additional Information

No response

@benmccann benmccann added the pkg:adapter-vercel Pertaining to the Vercel adapter label Feb 17, 2022
@bluwy
Copy link
Member

bluwy commented Feb 18, 2022

Does this happen on Vercel only? It seems like this is a Vite issue, specifically it's scanner where it's used during SSR builds too. Usually the scanner is invoked when there's no node_modules/.cache, so it some cases it may work locally unless you delete the cache and build again.

vitejs/vite#6863 is the only recent change to the scanner, but it shouldn't cause this issue I think. Does Vite 2.8.0 (not 2.8.1) work?

@murl-digital
Copy link
Author

Unfortunately, vite 2.8.0 doesn't work. I've also tried removing the adapter all together and there's no change, the build still fails, including with other adapters (I've tried static and nodejs so far)

@bluwy bluwy added vite p3-edge-case SvelteKit cannot be used in an uncommon way and removed pkg:adapter-vercel Pertaining to the Vercel adapter labels Feb 18, 2022
@Rich-Harris Rich-Harris added the bug Something isn't working label Mar 2, 2022
@murl-digital
Copy link
Author

murl-digital commented Mar 4, 2022

I've managed to reproduce the issue locally and have made a tiny amount of headway. I know nothing about how esbuild works but I think the issue is happening somewhere in the process of reading the text chunks from disk and passing them off to be parsed, specifically placing a console.log at esbuild's main.js line 760 spits out this:

console.log(packet.value)

{
  errors: [],
  outputFiles: [ { contents: [Uint8Array], path: '<stdout>' } ],
  rebuild: false,
  warnings: [],
  watch: false
}
{
  errors: [
    {
      detail: -1,
      location: [Object],
      notes: [],
      pluginName: '',
      text: 'Unterminated string literal'
    }
  ],
  outputFiles: [],
  rebuild: false,
  warnings: [],
  watch: false
}

While I have figured out how to work around this locally, I still have no way of getting a build to work in an environment like vercel's, unless I can manually create the build output and push it to vercel which I have no idea how to do

@Rich-Harris Rich-Harris added this to the 1.0 milestone Mar 5, 2022
@CaptainCodeman
Copy link
Contributor

This is being triggered by the commented out <script> tags lower down in the template, in the <svelte:head> block.

Change:

<svelte:head>
    <title>welcome | DRACONIUM</title>
    <!--eggs lmao-->
    <meta name='keywords' content='Draconium, music, eggs' />
    <meta name='description' content={metaDescription} />

    <!--<script src="//cdnjs.cloudflare.com/ajax/libs/ScrollMagic/2.0.7/ScrollMagic.min.js"></script>
    <script src="//cdnjs.cloudflare.com/ajax/libs/ScrollMagic/2.0.7/plugins/debug.addIndicators.min.js"></script>-->
</svelte:head>

to

<svelte:head>
    <title>welcome | DRACONIUM</title>
    <!--eggs lmao-->
    <meta name='keywords' content='Draconium, music, eggs' />
    <meta name='description' content={metaDescription} />
</svelte:head>

... and the issue goes away.

@benmccann
Copy link
Member

Thanks @CaptainCodeman! That investigation sped things up for me quite a bit. I sent a fix for the issue here: vitejs/vite#7202

@murl-digital
Copy link
Author

As ben said, thanks @CaptainCodeman! The fix works perfectly and I've had no other issues

@benmccann
Copy link
Member

The fix for this has been merged into Vite and will be included in Vite 2.9

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working p3-edge-case SvelteKit cannot be used in an uncommon way vite
Projects
None yet
Development

No branches or pull requests

5 participants