parcel: optimizer-terser: Unterminated string constant bug

πŸ› bug report

Steps to reproduce:

  1. Add this in your <script> tag in index.html
  var SOLIDUS$1 = 0x002F;         // U+002F SOLIDUS (/)

	// '/*' .* '*/'	
  var Comment = {
    }
  1. run parcel build index.html

  2. Output:

  Γ— Build failed.
  @parcel/optimizer-terser: Unterminated string constant

πŸ€” Expected Behavior

Should build

😯 Current Behavior

Build Fails

πŸ’ Possible Solution

  1. Remove // '/*' .* '*/' from your code

🌍 Your Environment

Software Version(s)
Parcel 2.0.0-beta.2
Node v15.7.0
npm/Yarn 7.4.3
Operating System Windows 10 Pro 20H2 build:19042.928

Thanks

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 15 (7 by maintainers)

Most upvoted comments

Well, for me the problem was fixed, that way(i.e having code in a file). You seems to be already using a separate file, so I guess they need to fix this.

I ran into the Unterminated string constant today as well when trying run parcel build on a project using the graphql-tag library for GraphQL queries.

The interesting part is that parcel serve command builds the code and launches the dev server without any issues!

I have the following code:

import gql from 'graphql-tag';

const query = gql`
    query myQuery($filter: [MyFilter]) {
        totalCount: getItemCount(filter: $filter) {
            count
        }
    }
`;
Software Version(s)
Parcel 2.0.0-beta.3.1
Node v14.17.0
npm/Yarn npm v7.11.2
Operating System Windows 10 Enterprise v1909, build: 18363.1440

So, is this an issue in Parcel or Terser then?

I found the issue! I cloned the repo and did not have any issues either. I thought that was weird so I did a winmerge on the working and broken directory and found that the only difference was the line endings!. Linux EOL (LF) work, but Windows (CR+LF) break everything. When I committed the repo I had git setup to normalize EOL to LF.

I corrected the repo so it is now broken. I think the only thing that needs to change is in the src folder so attached are the broken files in case github normalizes them again for some reason (I had to change multiple settings to disable the EOL conversion on commit) crlf-eol.zip

same for me in beta 3.1

using
<script src="../src/index.js" type="module"></script>

it happens when I add faker and call it: var faker = require("faker");

works with beta 1 and 2, though.

I am having the same issue with lit-element when the tagged templates have a new line (even if it is not the first character). All of my code is in its own TypeScript files (no HTML files at all since this project is a new JS lib).

Example:

render() {
    return html`
    <p>test</p>
    `;
  }

results in

Γ— Build failed.
@parcel/optimizer-terser: Unterminated string constant
  48 |     var data = $bQNpp$taggedTemplateLiteral([    
> 49 |         "
>    |        ^ Unterminated string constant
  50 | \n    <p>test</p>
  51 | \n    "
It's likely that Terser doesn't support this syntax yet.

but this works fine (NOTE no new lines in template literal)

render() {
    return html`<p>test</p>`;
  }

as does a normal template literal with new lines e.g.

var test = `
    test
    `;

Just like lanesawyer, parcel serve does not have this issue and everything works fine.

Software Version
Parcel 2.0.0-nightly.722 (also tried 2.0.0-nightly.718)
Node 15.12.0
NPM 7.6.3
OS Windows 10 Pro x64 v 20H2 build 19042.1052

Guess I’ll hijack your bug then since it’s the same error message even though you got around the problem 😁

No idea if it’s due to something funky that the graphql-tag library does or an underlying bug in the system, so we’ll see!

πŸ€” I am including it using a script tag, like this:

<script type="module" src="./index.tsx"></script>