自制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/lingojsin my Laravel project; the installation succeeded, and the package folder appears innode_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,提问作者עילאי אלמלם
相关产品推荐
相关产品推荐

