1

In my simple html + js project i have installed paper.js using npm install paper . But when i am trying to use a class new Point() , VS code is saying to convert it to E6 module . After click on the bulb i am continuously getting "Unexpected token (1:7)" for the line , import { Point } from "node_modules/paper/dist/paper-full.js"

My main file

            <!DOCTYPE html>
        <html>
        
        <head>
          <meta charset="UTF-8">
          <title>POI</title>
          <script type="text/javascript" src="node_modules/paper/dist/paper-full.js"></script>
          <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
        <script type="text/paperscript"  src="js/svg.js" canvas="canvas"></script>
        <link rel="stylesheet" href="css/style.css">
        </head>
        <body>
          <canvas id="canvas" resize></canvas>
        </body>
        </html> 

svg.js Where i am trying to read the Point Class which is paper-full.js

        import { Point } from "node_modules/paper/dist/paper-full.js"
        
        var pois = []  ; 
        
        $(function() {
        // Trying to load the class 
            new Point();
         });
Mohit H
  • 927
  • 3
  • 11
  • 26
  • Have you tried to remove the import statement? Since your loading paper.js via the script-tag inside the html document, I assume you don't need to import the Point in your js file. – fonzane Jul 05 '22 at 13:59
  • You need to import paper-full as ` – Ruan Mendes Jul 05 '22 at 14:01
  • @fonzane You should not manually modify files you don't own. Your assumptions are incorrect, that file is intended to be a module so there will be no global `Point` – Ruan Mendes Jul 05 '22 at 14:02
  • @Juan Mendes please have a look at the code examples here: http://paperjs.org/tutorials/getting-started/working-with-paper-js/ – fonzane Jul 05 '22 at 14:45

1 Answers1

-1

The problem is likely that you have installed paper.js via npm. Npm stands for node package manager, so the package you have installed is likely designed to work inside a nodejs application.

Nodejs is a javascript runtime to run locally on your machine, as opposed to javascript that usually runs inside the browser.

In order to make your project work, I advise you to download the paper.js file from the paper.js website and include it like they have done it here.

Good luck.

fonzane
  • 368
  • 1
  • 4
  • 16
  • You don't seem to understand that node modules can be used on the client also... – Ruan Mendes Jul 05 '22 at 16:31
  • It really is not a sign of professionality if you make assumptions on what people understand and what not. Please stay on the subject with your argument. Also, if you were able read closely, you could've read that I said likely and not definitely. I'm aware that node modules can be used on the client, but usually that is not their purpose... – fonzane Jul 06 '22 at 12:32
  • I did not make assumptions, you had made multiple erroneous statements and are posting something as an answer that is clearly inaccurate. There's no need to manually download the file. – Ruan Mendes Jul 06 '22 at 14:17