提问者:小点点

为什么我的NPM包在Laravel中不工作?


我为自己创建了一个npm包,但当我试图在laravel中使用它时,它返回了一个ReferenceError。 下面是我所做的:我遵循了关于如何启动npm包的教程,它的工作方式应该是在标准JavaScript中工作的。 所以我在我的laravel应用程序中做了以下操作:

npm install @ilayalmalem/lingojs

它工作了,并且在node_modules文件夹中实例化了一个文件夹。

我在app.js中添加了以下内容:

window.lingo = require('@ilayalmalem/lingojs');

但当我尝试在刀片视图中使用它时,就像这样:

var lingo = new Lingo('.s',{
     Models:{
       model1:'d'
     }
});

它返回:

Uncaught ReferenceError: Lingo is not defined

下面是我的Package.json:

{
  "name": "@ilayalmalem/lingojs",
  "version": "0.0.4",
  "description": "Write less javascript.",
  "main": "index.js",
  "scripts": {
    "test": "lingo"
  },
  "dependencies": {
    "jquery": "^3.2.1"
  },
  "repository": {
    "type": "git",
    "url": "git+https://github.com/ilayalmalem/Lingo.js.git"
  },
  "keywords": [
    "LingoJS",
    "Backend",
    "communication"
  ],
  "author": "Ilay David Almalem",
  "license": "ISC",
  "bugs": {
    "url": "https://github.com/ilayalmalem/Lingo.js/issues"
  },
  "homepage": "https://github.com/ilayalmalem/Lingo.js#readme"
}

下面是我实例化Lingo类的方法:

class Lingo {
...code
}

如果您真的对代码感兴趣,请查看以下代码:https://github.com/ilayalmalem/lingo.js

如果你需要更多的信息,只管评论。


共1个答案

匿名用户

伙计们,如果遇到这个问题,只需在index.js中添加这一行:

module.exports = your class;

别忘了跑:

node your_main_file.js

在命令行中。