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

bug: ERROR ReferenceError: require is not defined #50

Closed
hramberger opened this issue Feb 16, 2022 · 28 comments
Closed

bug: ERROR ReferenceError: require is not defined #50

hramberger opened this issue Feb 16, 2022 · 28 comments
Assignees
Labels
bug Something isn't working

Comments

@hramberger
Copy link
Contributor

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",
	...
  }
@werthdavid werthdavid self-assigned this Feb 17, 2022
@werthdavid werthdavid added the bug Something isn't working label Feb 17, 2022
@werthdavid
Copy link
Owner

I guess I broke SSR now but please try 1.14.1

@hramberger
Copy link
Contributor Author

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.

@werthdavid
Copy link
Owner

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

@hramberger
Copy link
Contributor Author

hramberger commented Feb 17, 2022

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

@werthdavid
Copy link
Owner

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

@hramberger
Copy link
Contributor Author

hramberger commented Feb 17, 2022

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.

@rbalet
Copy link
Contributor

rbalet commented Mar 1, 2022

@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

#51

@rbalet
Copy link
Contributor

rbalet commented Mar 3, 2022

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

@werthdavid
Copy link
Owner

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
Copy link
Owner

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

@rbalet
Copy link
Contributor

rbalet commented Mar 3, 2022

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

@hramberger
Copy link
Contributor Author

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

@werthdavid werthdavid reopened this Mar 4, 2022
@rbalet
Copy link
Contributor

rbalet commented Mar 4, 2022

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...

@daniloMogin
Copy link

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"

@moneyfather
Copy link

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

@lalo-mx
Copy link

lalo-mx commented Mar 17, 2022

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

You can run 1.13.2

@werthdavid
Copy link
Owner

Is this still the case with 2.0.1?

@Sergiobop
Copy link

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)

@lalo-mx
Copy link

lalo-mx commented Mar 22, 2022

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

@hramberger
Copy link
Contributor Author

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

@werthdavid
Copy link
Owner

I can reproduce it... on it!

@werthdavid
Copy link
Owner

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

@wiemax1093
Copy link

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

@Sergiobop
Copy link

Is the bug fixed with this one @werthdavid @delyethan ? #60

If that's the case we can close this one and #53 (Also do a release?)

BIG THANKS for your work!

@werthdavid
Copy link
Owner

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

@rbalet
Copy link
Contributor

rbalet commented Sep 9, 2022

@hramberger Should be fixed, can you try it?

@hramberger
Copy link
Contributor Author

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

@rbalet
Copy link
Contributor

rbalet commented Sep 13, 2022

@werthdavid feel free to close that issue :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

8 participants