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

SyntaxError: Identifier 'hue' has already been declared #1525

Closed
nesbocaj opened this issue May 12, 2019 · 2 comments
Closed

SyntaxError: Identifier 'hue' has already been declared #1525

nesbocaj opened this issue May 12, 2019 · 2 comments
Labels

Comments

@nesbocaj
Copy link

nesbocaj commented May 12, 2019

Stencil version:

@stencil/core@0.18.1

I'm submitting a:

[x] bug report
[ ] feature request
[ ] support request => Please do not submit support requests here, use one of these channels: https://stencil-worldwide.herokuapp.com/ or https://forum.ionicframework.com/

Current behavior:

The component builds correctly but does not render and instead results in the following error message in the browser console:

SyntaxError: Identifier 'hue' has already been declared "http://localhost:3333/build/charts/spark-line.entry.js"

Expected behavior:

The component should build and render correctly with no error message in the browser console.

Steps to reproduce:

  1. $ npm init stencil and pick component
  2. $ npm install --save-dev @stencil/core@0.18.1
  3. $ npm install --save d3
  4. $ npm install --save-dev @types/d3
  5. $ npm start

Related code:

./src/components/spark-line/spark-line.tsx

import { Component, Prop } from "@stencil/core";
import * as d3 from "d3";

@Component({
  tag: "spark-line",
  shadow: true
})
export class SparkLine {
  private xScale: d3.ScaleTime<number, number>;

  private yScale: d3.ScaleLinear<number, number>;

  private linePath: string;

  @Prop()
  public data: Array<{ time: Date; price: number }> = [];

  @Prop()
  public width: number = 640;

  @Prop()
  public height: number = 200;

  public componentWillLoad() {
    this.xScale = d3.scaleTime().range([0, this.width]);
    this.yScale = d3.scaleLinear().range([this.height, 0]);

    this.updateDomain();
  }

  public componentWillUpdate() {
    this.updateDomain();
  }

  public render() {
    return (
      <svg width={this.width} height={this.height}>
        <g>
          <path d={this.linePath} fill="transparent" stroke="#AAA" />
        </g>
      </svg>
    );
  }

  private updateDomain() {
    if (!this.data || this.data.length === 0) {
      return;
    }

    const timeExtent = d3.extent(this.data, datum => datum.time);
    const priceExtent = d3.extent(this.data, datum => datum.price);

    this.xScale.domain(timeExtent);

    this.yScale.domain(priceExtent)
      .nice();

    const lineGenerator = d3
      .line<{ time: Date; price: number }>()
      .x(datum => this.xScale(datum.time))
      .y(datum => this.yScale(datum.price));

    this.linePath = lineGenerator(this.data);
  }
}

./src/index.html

<!DOCTYPE html>
<html dir="ltr" lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=5.0">
  <title>Stencil Component Starter</title>
  <script src="/build/charts.js"></script>

</head>
<body>
  <spark-line></spark-line>
</body>
</html>

./stencil.config.ts

import { Config } from "@stencil/core";

export const config: Config = {
  namespace: "charts",
  outputTargets: [
    { type: "dist" },
    { type: "docs" },
    {
      type: "www",
      serviceWorker: null, // disable service workers
    },
  ],
};

Other information:

@ionitron-bot ionitron-bot bot added the triage label May 12, 2019
@nesbocaj
Copy link
Author

Adding --es5 to the start script in package.json results in the expected behaviour in Firefox, but not in Chrome.

{
  ...
  "scripts": {
    ...
    "start": "stencil build --dev --watch --serve --es5",
    ...
  }
  ...
}

@manucorporat
Copy link
Contributor

It might be related with rollup/rollup#2865

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

No branches or pull requests

2 participants