ngx-kjua icon indicating copy to clipboard operation
ngx-kjua copied to clipboard

bug: ERROR ReferenceError: require is not defined

Open hramberger opened this issue 2 years ago • 25 comments

Description

After the update to 1.14.0 the NgxKjuaComponent throws the following error when it is been initialized / first called in our application (see Stacktrace for more details):

ERROR ReferenceError: require is not defined The compilation on the other hand runs without any errors. Moreover version 1.13.2 works fine in the exact same setting. Do I need a special configuration (e.g special compiler options) to make version 1.14.0 work?

Stacktrace

main.js ERROR ReferenceError: require is not defined
    at new NgxKjuaComponent
    at NodeInjectorFactory.NgxKjuaComponent_Factory [as factory]
    at getNodeInjectable
    at instantiateAllDirectives
    at createDirectivesInstances
    at ɵɵelementStart
    at Module.ɵɵelement
    at MyComponent_Template
    at executeTemplate
    at renderView

The references in the stacktrace point to the following code in the transpiled main.js which is part of the class cunstructor of NgxKjuaComponent:

    if ((0,_angular_common__WEBPACK_IMPORTED_MODULE_1__.isPlatformServer)(this.platformId)) {
      return;
    } else if (!kjua) {
      kjua = require("kjua-svg");
    }

Used versions

  "dependencies": {
	...
    "@angular/common": "13.2.2",
    "@angular/compiler": "13.2.2",
    "@angular/core": "13.2.2",
	...
    "kjua-svg": "1.13.1", (as defined in the peerDependencies)
    "ngx-kjua": "1.14.0",
	...
  },
  "devDependencies": {
	...
    "@angular-devkit/build-angular": "13.2.3",
    "@angular/cli": "13.2.3",
    "@angular/compiler-cli": "13.2.2",
    "@types/node": "17.0.18",
    "typescript": "4.4.4",
	...
  }

hramberger avatar Feb 16 '22 12:02 hramberger

I guess I broke SSR now but please try 1.14.1

werthdavid avatar Feb 17 '22 12:02 werthdavid

Thanks for the quick response. The original ReferenceError does not exist anymore in version 1.14.1. Unfortunately now I get a TypeError with the following stacktrace:

ERROR TypeError: (kjua_svg__WEBPACK_IMPORTED_MODULE_0___namespace_cache || (intermediate value)(intermediate value)) is not a function
    at NgxKjuaComponent.get template [as template]
    at NgxKjuaComponent.renderCode
    at NgxKjuaComponent.updateView
    at NgxKjuaComponent.ngAfterViewInit
    at callHook
    at callHooks
    at executeInitAndCheckHooks
    at refreshView
    at refreshComponent
    at refreshChildComponents

The return value of getTemplate() within the NgxKjuaComponent seems to still cause an issue.

hramberger avatar Feb 17 '22 13:02 hramberger

dang it... I guess the fix has to be implemented in "kjua-svg"..

werthdavid avatar Feb 17 '22 13:02 werthdavid

Is another issue required for kjua-svg (i.e. in https://github.com/werthdavid/kjua)?

hramberger avatar Feb 17 '22 14:02 hramberger

I guess. I'm the maintainer of that as well so in the end it doesn't make a difference.. I don't have time until next week though, PRs are highly appreciated if you have any idea how to fix this

werthdavid avatar Feb 17 '22 14:02 werthdavid

No problem at all since version 1.13.2 works fine for me. So the fix is not that urgent to me :-). Unfortunately I have no idea what could be the cause of the error. I'll take a look at it, but I'm not the most experienced in the JS libraries area.

hramberger avatar Feb 17 '22 14:02 hramberger

@werthdavid I had the same error and saw that you weren't exporting the project as Angular recommends it. I decided to refactor it a little bit.

I've updated the version to be v2.0.0 since it's kind of a big changes in your code.

Hope this will help

https://github.com/werthdavid/ngx-kjua/pull/51

rbalet avatar Mar 01 '22 17:03 rbalet

@werthdavid could you release a new version, now that the cod should be fixed?

rbalet avatar Mar 03 '22 06:03 rbalet

I'm on it. Currently testing it in one of my projects. I'll remove some unnecessary stuff and then make a release by the end of the day

werthdavid avatar Mar 03 '22 07:03 werthdavid

The end of the day came sooner than expected 😅 2.0.0 is out, let me know if you experience any problems

werthdavid avatar Mar 03 '22 07:03 werthdavid

@werthdavid I confirm that this does solve the issue, you may close this issue

rbalet avatar Mar 03 '22 08:03 rbalet

Unfortuately I still get the same TypeError with version 2.0.0. Do I need to do more just updating ngx-kjua?

hramberger avatar Mar 04 '22 08:03 hramberger

Unfortuately I still get the same TypeError with version 2.0.0. Do I need to do more just updating ngx-kjua?

Indeed, I don't know what I did test, sorry for my mistake.

Then I do not understand the error...

rbalet avatar Mar 04 '22 08:03 rbalet

Hello, I'm also having the same TypeError ERROR TypeError: (kjua_svg__WEBPACK_IMPORTED_MODULE_0___namespace_cache || (intermediate value)(intermediate value)) is not a function at NgxKjuaComponent.get template [as template] at NgxKjuaComponent.renderCode at NgxKjuaComponent.updateView at NgxKjuaComponent.ngAfterViewInit at callHook at callHooks at executeInitAndCheckHooks at refreshView at refreshComponent at refreshChildComponents

and I'm using angular 13.2.2, "kjua-svg": "^1.13.1" and "ngx-kjua": "^2.0.0"

daniloMogin avatar Mar 05 '22 19:03 daniloMogin

hi ,Is it possible for me to run a compatible older version, ?

moneyfather avatar Mar 17 '22 12:03 moneyfather

hi ,Is it possible for me to run a compatible older version, ?

You can run 1.13.2

lalo-mx avatar Mar 17 '22 13:03 lalo-mx

Is this still the case with 2.0.1?

werthdavid avatar Mar 22 '22 12:03 werthdavid

This one is still appearing @werthdavid. I had to downgrade to 1.13.2

core.mjs:6485 ERROR TypeError: (kjua_svg__WEBPACK_IMPORTED_MODULE_0___namespace_cache || (intermediate value)(intermediate value)) is not a function
    at NgxKjuaComponent.get template [as template] (ngx-kjua.mjs:114:20)
    at NgxKjuaComponent.renderCode (ngx-kjua.mjs:118:27)
    at NgxKjuaComponent.updateView (ngx-kjua.mjs:143:22)
    at NgxKjuaComponent.ngAfterViewInit (ngx-kjua.mjs:82:14)
    at callHook (core.mjs:2542:1)
    at callHooks (core.mjs:2511:1)
    at executeInitAndCheckHooks (core.mjs:2462:1)
    at refreshView (core.mjs:9555:1)
    at refreshComponent (core.mjs:10655:1)
    at refreshChildComponents (core.mjs:9280:1)

Sergiobop avatar Mar 22 '22 14:03 Sergiobop

With 2.0.1

 Uncaught TypeError: qn is not a function
    at n.get template [as template] (1639.7cb16e9dc89963d1.js:formatted:2136:28)
    at n.renderCode (1639.7cb16e9dc89963d1.js:formatted:2163:36)
    at n.updateView (1639.7cb16e9dc89963d1.js:formatted:2179:96)
    at ngOnChanges (1639.7cb16e9dc89963d1.js:formatted:2133:50)
    at n.er (main.a26327982be8bec6.js:1:2211432)
    at ll (main.a26327982be8bec6.js:1:2216084)
    at al (main.a26327982be8bec6.js:1:2215880)
    at ca (main.a26327982be8bec6.js:1:2215550)
    at Of (main.a26327982be8bec6.js:1:2240666)
    at Object.Mf (main.a26327982be8bec6.js:1:2240560) 

image

image

lalo-mx avatar Mar 22 '22 14:03 lalo-mx

I also get the same error as @Sergiobop with version 2.0.1.

hramberger avatar Mar 22 '22 15:03 hramberger

I can reproduce it... on it!

werthdavid avatar Mar 23 '22 11:03 werthdavid

I did play around with tsconfig but after a little research it seems to be a problem with ng-packagr... https://github.com/ng-packagr/ng-packagr/issues/2215 I will for now unpublish >=2.0.0 as 1.x works and create a new version when ng-packagr fixed the issue

werthdavid avatar Mar 28 '22 12:03 werthdavid

just had exactly the same error: core.mjs:6485 ERROR TypeError: (kjua_svg__WEBPACK_IMPORTED_MODULE_0___namespace_cache || (intermediate value)(intermediate value)) is not a function

despite my package.json showed me 1.13.2 as ngx-kju (kju-svg: 1.13.1) - moved to a new workstation so maybe somehow it upgraded it upon installing all packages newly (and still showing old version). Upgraded it to 1.14.x to check but same error, downgraded back to 1.13.2 fixed it, all problems gone.

BTW: the upper error is only showed in "dev mode" if I build my application it shows the "other" similar one: Uncaught TypeError: Yge is not a function

wiemax1093 avatar May 02 '22 12:05 wiemax1093

Is the bug fixed with this one @werthdavid @delyethan ? https://github.com/werthdavid/ngx-kjua/pull/60

If that's the case we can close this one and https://github.com/werthdavid/ngx-kjua/issues/53 (Also do a release?)

BIG THANKS for your work!

Sergiobop avatar Jul 11 '22 10:07 Sergiobop

I fear as stated above the problem comes from ng-packagr... still waiting for a fix

werthdavid avatar Jul 11 '22 18:07 werthdavid

@hramberger Should be fixed, can you try it?

rbalet avatar Sep 09 '22 11:09 rbalet

I checked version 2.0.2 and it seems to work as expected again. Thanks for the fix!

hramberger avatar Sep 13 '22 16:09 hramberger

@werthdavid feel free to close that issue :)

rbalet avatar Sep 13 '22 16:09 rbalet