模块未提供名为“默认”的导出

时间:2019-08-02 21:14:41

标签: javascript

有两个类似的问题,但是他们的解决方案要么是解决方案,要么停止使用模块,要么不能解决我的问题。这些模块似乎无法正常工作。我正在使用节点通过本地主机服务器运行此操作,而我只是更新了节点。我确定是导致此错误的原因,所以我将所有文件放在下面。

我收到一条错误消息,指出我的drawLine模块未导出称为default的东西-为什么?

它引发的错误是:

Uncaught SyntaxError: The requested module './drawLine.js' does not provide 
an export named 'default'

此外,如果我将drawLine模块更改为仅使用export {drawLine}正常导出,并使用import。{drawLine}从“ ./drawLine.js”导入;

它引发错误:

Uncaught SyntaxError: The requested module './drawLine.js' does not provide 
an export named 'drawLine'

app.js:

 import drawLine from "./drawLine.js";

 console.log(imports.drawLine);
 let line= imports.drawLine(0,100);
 let body= document.getElementsByTagName("body")[0];
 body.append(line);

drawLine.js

function drawLine(x,y){
   let canvas = document.createElement("canvas");
   let canvasContext= canvas.getContext("2d");
   canvasContext.beginPath();
   canvasContext.moveTo(0,0);
   canvasContext.lineTo(x,y);
   canvasContext.stroke();

  return canvas;
}

export default drawLine;

index.html:

 <!DOCTYPE html>
 <html>
      <head>
          <meta charset="utf-8">

      </head>
      <body>
          <p>hello</p>
          <script type="module" src="app.js"></script>
      </body>
  </html>

nodeServer.js

 let HTTP = require("http");
 let fs = require("fs");

  let requestListener = function(req, res){
      let url = req.url;
      console.log(url);

      if(url === "/index.html"){
          fs.readFile("index.html", function(err, data){
             if(err){
                  throw err;
             }

              else{
                 res.setHeader("Content-Type", "Text/html");
                  res.write(data);
                  res.end();
              }
          });
      }
      else if(url === "/app.js" || url === "/drawLine.js" || url === "/canterSet.js") {
          fs.readFile("app.js", function(err, data){
              if(err){
                 throw err;
              }

              else{
                  res.setHeader("Content-Type", "application/javascript");
                  res.write(data);
                  res.end();
              }
           });
      }
 }

  let server = HTTP.createServer(requestListener);

  server.listen(8080);

0 个答案:

没有答案