Uncaught SyntaxError: невозможно использовать оператор импорта вне модуля

Может кто-нибудь помочь, я пробовал использовать type = module и type = text / javascript, но бот не запускается. Что я должен делать?

Это страница index.html, на которой я получаю ввод файла от пользователя, и данные будут проанализированы в index.js.

<!DOCTYPE html>
<html>
<head>
  <title>D3 Evalusation</title>

  <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.13.5/xlsx.full.min.js"></script

  <script type="module" src="https://unpkg.com/[email protected]/dist/d3.min.js"></script>

  <link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<h1 id="header">Import your Data</h1>

<div class="input_form>">
  <form class="input_form" style="border:1px solid #ccc" method="POST">

    <h1>Please insert your data</h1>

    <label id="fname">First Name</label>
    <input type="text" placeholder="John" name="name" required><br/><br/>

    <label id="lname">Last Name</label>
    <input type="text" placeholder="Doe" name="name" required><br/><br/>

    <label id="email">Email</label>
    <input type="text" placeholder="Enter email" name="email" required><br/><br/>

    <label id="phone">Phone No.</label>
    <input type="text" placeholder="Enter phone" name="phone" required><br/><br/>

    <input type="file"  id="upload_file" accept=".xls,.xlsx,.csv"/></br></br>

    <label id="characteristic" >Please choose 1 characteristic to be grouped by</label>
    <div id="columns"></div>

    <div class="clearfix">
      <a href="Homepage.html">
        <button type="button" class="cancelbtn">Cancel</button></a>
      <button type="submit" class="signupbtn">Sample</button>
    </div>

  </form>
</div>
</body>

<script type="text/javascript" src="index.js"></script>
</html>

Это файл index.js

 import {
    select
  } from 'd3';

  let selectedFile;

  var upload = document.getElementById('upload_file');
    upload.addEventListener("change",(event)=>{
      selectedFile = event.target.files[0];

      if(selectedFile){
        let fileReader = new FileReader();
          fileReader.readAsBinaryString(selectedFile);
          fileReader.onload = (event) => {
          let data = event.target.result;
          let wb = XLSX.read(data,{type:"binary"});

          wb.SheetNames.forEach(sheet => {
            let dataRow = XLSX.utils.sheet_to_row_object_array(wb.Sheets[sheet]);
            JSON.stringify(dataRow,undefined,4);
          })
            select("column").call(dropdownMenu,{
              options:dataRow.columns
            })
            }
        }
    });


Отвечает ли это на ваш вопрос? Uncaught SyntaxError: невозможно использовать оператор импорта вне модуля при импорте ECMAScript 6   —  person Muhd Danish    schedule 18.05.2021

нет, я уже добавил модуль типа как в json, так и в html, все равно получил ту же ошибку   —  person Muhd Danish    schedule 18.05.2021

См. также:  Как вернуть файл YAML в качестве выходного артефакта из Lambda в CodePipeline
Понравилась статья? Поделиться с друзьями:
IT Шеф
Комментарии: 1
  1. Muhd Danish

    Это известная проблема с D3. Пытаться:

    import * as d3 from 'd3';
    
    d3.select(...)
    
    

    все еще не работает :( person Muhd Danish; 18.05.2021

Добавить комментарий

;-) :| :x :twisted: :smile: :shock: :sad: :roll: :razz: :oops: :o :mrgreen: :lol: :idea: :grin: :evil: :cry: :cool: :arrow: :???: :?: :!: