gijgo icon indicating copy to clipboard operation
gijgo copied to clipboard

Webpack - gj is not defined

Open rafakwolf opened this issue 7 years ago • 12 comments

I'm using gijgo from npm

importing this way, after jquery imports:

import 'modules/gijgo/js/gijgo.min';
import 'modules/gijgo/js/messages/messages.pt-br.min';
import 'modules/gijgo/css/gijgo.min.css';

then generating the bundle with webpack 4

but getting this error gj is not defined

image

Thanks for any help

rafakwolf avatar Jun 30 '18 16:06 rafakwolf

I got it working using ver 1.9.6

in app.js: import "gijgo";

and app.scss: @import "~gijgo/css/gijgo";

also in webpack.config.js, I did following to make the fonts available:

plugins: [
    new CopyWebpackPlugin([
                           { from: 'node_modules/gijgo/fonts', to: '../fonts' }
                         ]),

ver 1.9.7 is broken, yet to try ver 1.9.9

Hope this helps.

goravbhootra avatar Jul 24 '18 07:07 goravbhootra

I had the same problem :(

atakajlo avatar Aug 10 '18 18:08 atakajlo

Same here, gj is not being exported so it cannot be used

cuartas15 avatar Feb 08 '19 05:02 cuartas15

I don't have experience with Webpack. Could you give me replication steps about this. gj is the main object/variable that contains all methods and default configurations for the controls. How to configure export of this variable?

atatanasov avatar Feb 14 '19 08:02 atatanasov

Just look at examples like moment.js and javascript export functionality added since ECMAscript 2015 (I think)

cuartas15 avatar Feb 18 '19 17:02 cuartas15

I have experience using Webpack only with Angular and everything looks good when I do that. You can see an example for that in 'src\app\datepicker.demo.component.ts' at https://github.com/atatanasov/gijgo-angular-wrappers. You can also remove the comment from line 30 to see that this works good with locales as well. You can see an instructions how to run that on a development server at the end of the https://github.com/atatanasov/gijgo-angular-wrappers read me section

atatanasov avatar Feb 25 '19 08:02 atatanasov

This is specific to Angular, it won't work with other frameworks out there. The advantage of exporting is that it can work with anything.

cuartas15 avatar Feb 26 '19 20:02 cuartas15

Do you think that If I add export { gj }; line at the end of my js file, this is going to resolve the "gj is not defined" error.

Please, advise. Atanas

atatanasov avatar Feb 26 '19 20:02 atatanasov

It's a little tricky with your code and I'm not pretty sure if I'm using the best practices:

  • Had to import jQuery on gijgo.js, otherwise is not recognized import jQuery from 'jquery'; I assume you have to import it from the node module in package.json

  • Had to declare each variable the conventional way, meaning, anything that starts with: variable = something had to be changed to: var variable = something

  • Then do export default gj; at the end of the file

cuartas15 avatar Feb 27 '19 07:02 cuartas15

@cuartas15 - Thanks for the help. We can't change this in the next 1.9 version, but we are going to add support about this in version 2.0. I would ask the community to use your workaround for now and be patience for the next major release.

atatanasov avatar Mar 13 '19 07:03 atatanasov

I ran into the same issue here. I solved it by using webpack's script-loader.

https://webpack.js.org/loaders/script-loader/

Once you have script loader, you can import Gijgo by

import 'script-loader!gijgo';

gj is now loaded. You can import the "message" files right after that line without a problem, if that was your issue.

import 'script-loader!gijgo';
import 'gijgo/js/messages/messages.es-es';

Note that this workaround pollutes the global namespace.

alanrodas avatar Mar 20 '19 21:03 alanrodas

It's a little tricky with your code and I'm not pretty sure if I'm using the best practices:

* Had to import jQuery on gijgo.js, otherwise is not recognized
  `import jQuery from 'jquery';`
  I assume you have to import it from the node module in package.json

* Had to declare each variable the conventional way, meaning, anything that starts with:
  `variable = something`
  had to be changed to:
  `var variable = something`

* Then do `export default gj;` at the end of the file

This doesn't work for me.

@atatanasov is version 2.0 on the way?

nzurita avatar Sep 13 '22 11:09 nzurita