Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uncaught ReferenceError: global is not defined #200

Closed
ItaloCobains opened this issue May 14, 2024 · 4 comments
Closed

Uncaught ReferenceError: global is not defined #200

ItaloCobains opened this issue May 14, 2024 · 4 comments

Comments

@ItaloCobains
Copy link

I've trying use jkanban in my rails project, but i have this error.

index.js:2 Uncaught ReferenceError: global is not defined
    at node_modules/custom-event/index.js (index.js:2:25)
    at __require (application.js:14:46)
    at node_modules/crossvent/src/crossvent.js (crossvent.js:3:19)
    at __require (application.js:14:46)
    at node_modules/dragula/dragula.js (dragula.js:4:17)
    at __require (application.js:14:46)
    at jkanban.js:10:15
    at application.js:100:46

how to fix this ?

@marcosrocha85
Copy link
Contributor

Hello Italo, can you share how are you including jKanban to your rails project?

@ItaloCobains
Copy link
Author

import { Controller } from "@hotwired/stimulus";
import axios from "axios";
import "jkanban";
import { get, map, sample } from 'lodash-es';

// Connects to data-controller="board"
export default class extends Controller {
    HEADERS = { 'ACCEPT': 'application/json' }
    BACKGROUND_COLORS = ['bg-blue-700', 'bg-green-700', 'bg-red-700', 'bg-yellow-700', 'bg-indigo-700', 'bg-pink-700', 'bg-purple-500', 'bg-gray-500', 'bg-teal-500', 'bg-orange-500']

    connect() {
        axios.get(this.element.dataset.apiUrl, {
           headers: this.HEADERS
        }).then((response) => {
           this.buildKanban(this.buildBoards(response.data))
       })
    }

    // buildClassList(classList) {
    //     if (isNull(classList)) return '';

    //     return classList.split(' ').join(',')
    // }

    buildClassList() {
        return `text-white, ${sample(this.BACKGROUND_COLORS)}`
    }

    buildItens(itensData) {
        return map(itensData['data'], (item) => {
            return {
                'id': get(item, 'id'),
                'title': get(item, 'attributes.title'),
                'class': this.buildClassList()
            }
        })
    }

    buildBoards(bordsData) {
        return map(bordsData['data'], (board) => {
            return {
                'id': get(board, 'id'),
                'title': get(board, 'attributes.title'),
                'class': this.buildClassList(),
                'item': this.buildItens(get(board, 'attributes.items'))
            }
        })
    }

    buildKanban(boards) {
        new jKanban({
            element: `#${this.element.id}`, 
            boards,
            itemAddOptions: {
                enabled: true,       
            }        
        })
    }
}

@ItaloCobains
Copy link
Author

I fix with this.

globalThis.global = globalThis

i'm import this file in my application.js, but i dont know if this is best way

@marcosrocha85
Copy link
Contributor

I made a kanban in a CodeIgniter application before. I imported the compiled jkanban.min.js at the page I needed. I don't know how it works on rails, but if it works, it fits.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants