通过NPM安装的JS文件的JavaScript读取类

发布于 2025-02-12 23:59:41 字数 1077 浏览 1 评论 0原文

在简单的HTML + JS项目中,我使用NPM安装纸安装了Paper.js。但是,当我尝试使用类新点()时,VS代码说将其转换为E6模块。单击灯泡后,我将不断获得该行的“意外令牌(1:7)

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

” 阅读纸上的积分课

        import { Point } from "node_modules/paper/dist/paper-full.js"
        
        var pois = []  ; 
        
        $(function() {
        // Trying to load the class 
            new Point();
         });

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();
         });

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

内心荒芜 2025-02-19 23:59:41

问题可能是您通过NPM安装了Paper.js。 NPM代表Node Package Manager,因此您安装的软件包可能是为在Nodejs应用程序中工作的。

Nodejs是一个JavaScript运行时,可以在您的计算机上本地运行,而不是通常在浏览器内部运行的JavaScript。

为了使您的项目起作用,我建议您从 Paper.js网站将其包括在内,就像他们完成的那样在这里

祝你好运。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文