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();
         });
4
  • 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. Commented Jul 5, 2022 at 13:59
  • You need to import paper-full as <script type="module"> so that the engine will recognize import statements. See developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules You can only use import and export statements inside modules, not regular scripts. Commented Jul 5, 2022 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 Commented Jul 5, 2022 at 14:02
  • @Juan Mendes please have a look at the code examples here: paperjs.org/tutorials/getting-started/working-with-paper-js Commented Jul 5, 2022 at 14:45

1 Answer 1

-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.

Sign up to request clarification or add additional context in comments.

3 Comments

You don't seem to understand that node modules can be used on the client also...
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...
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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.