You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

自制NPM包在Laravel中触发ReferenceError问题求助

ReferenceError: Lingo is not defined when using custom NPM package in Laravel

I've developed a custom NPM package @ilayalmalem/lingojs that works perfectly in a standard JavaScript environment, but when I try to use it in a Laravel project, I get a ReferenceError: Lingo is not defined in the browser console. Here's my step-by-step workflow:

  • Initialized the NPM package following standard tutorials, and confirmed its functionality works as expected in a vanilla JS setup.
  • Ran npm install @ilayalmalem/lingojs in my Laravel project; the installation succeeded, and the package folder appears in node_modules.
  • Added this line to my app.js:
    window.lingo = require('@ilayalmalem/lingojs');
    
  • Tried to instantiate the class in a Blade view with:
    var lingo = new Lingo('.s',{ Models:{ model1:'d' } });
    

At this point, the console throws the error:

Uncaught ReferenceError: Lingo is not defined

Here's the package.json configuration for my NPM package:

{
  "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"
}

The Lingo class in my package is defined using:

class Lingo {
  // ... class implementation code
}

If any additional details are needed to diagnose this issue, feel free to ask.

内容的提问来源于stack exchange,提问作者עילאי אלמלם

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.08 14:13:11