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

ReferenceError: Element is not defined - nodejs-pal #243

Closed
dweber019 opened this issue Nov 8, 2017 · 6 comments
Closed

ReferenceError: Element is not defined - nodejs-pal #243

dweber019 opened this issue Nov 8, 2017 · 6 comments
Assignees

Comments

@dweber019
Copy link

I'm submitting a bug report

  • Library Version:
    1.6.2 / 2.0.0

Please tell us about your environment:

  • Operating System:
    OSX

  • Node Version:
    6.11.4

  • NPM Version:
    3.10.10

  • JSPM OR Webpack AND Version
    webpack 3.8.1

  • Browser:
    Jest

  • Language:
    TypeScript 2.6.1

Setup:
I'm using a slighly changed version of the Aurelia Skeleton for Webpack and Typescript.
There I have tests, which mock i18n => https://github.com/w3tecch/aurelia-typescript-boilerplate/blob/feature/dependency-update/test/unit/app.spec.ts#L50

I have now upgraded to the latest dependencies regarding Aurelia and everything from building to running the app in the browser (even e2e test) work fine.

Sadly the jest unit tests are broken with the following errror:

ReferenceError: Element is not defined

      at Object.<anonymous> (node_modules/aurelia-i18n/dist/commonjs/t.js:59:24)
      at Object.<anonymous> (node_modules/aurelia-i18n/dist/commonjs/aurelia-i18n.js:34:10)
      at Object.<anonymous> (src/app.spec.ts:2:16)

This error disappears when I remove aurelia-i18n.

There is no difference in using version 1.6.2 or 2.0.0. So I think it has something to do with the other Aurelia dependencies, which are the lastest as of today.

The tests in aurelia-i18n repository are using aurelia-pal-browser. On the other hand the Aurelia-CLI and the Aurelia Skeleton are using the aurelia-pal-nodejs and so do I. Maybe this makes some difference regarding this issue.

If you like to reproduce checkout this branch, yarn install and run npm test:
https://github.com/w3tecch/aurelia-typescript-boilerplate/tree/feature/dependency-update

Thanks for any advise / help

@zewa666 zewa666 self-assigned this Nov 8, 2017
zewa666 added a commit that referenced this issue Nov 8, 2017
window and Element injects are now requested via the PAL
so that executing tests with node-based unit test runners like
Jest do not break

related issue #243
@zewa666
Copy link
Member

zewa666 commented Nov 8, 2017

@dweber019 let me first say thanks for the great issue report and the example to reproduce the issue. This makes fixing things much easier :)

So the reason was that the i18n plugin still directly referenced window instead PLATFORM.global and injected the Element instead of DOM.Element provided by the specific PAL.

I've checked out your example and with these fixes it works. With the next release everything should be ok. Thanks again for the feedback

@dweber019
Copy link
Author

@zewa666 awesome! Really like you guys speed on fixing things.

Do you have any estimate on when this fix will be published?

@zewa666
Copy link
Member

zewa666 commented Nov 9, 2017

I've already contacted @EisenbergEffect and queued this up for the next release cycle. So as soon as his time permits this will be pushed. In the meantime if this is a blocker for you, you can fork the repo, build the dist files and reference your fork for the time being.

@atsu85
Copy link
Contributor

atsu85 commented Nov 9, 2017

@EisenbergEffect, @zewa666 i think this kind of problems could be automatically detected with aurelia-template-lint - it just needs small improvements (additional rule, that would alert via linter when using globals, that don't work with aurelia-pal-nodejs)

@zewa666
Copy link
Member

zewa666 commented Nov 16, 2017

@dweber019 please check out the latest release, closing this for now. if there are any issues please report back.

@zewa666 zewa666 closed this as completed Nov 16, 2017
@dweber019
Copy link
Author

Thanks a lot. Amazing speed 👍

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

3 participants