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: MouseEvent is not defined (Angular 2 Universal) #964

Closed
hongbo-miao opened this issue Sep 14, 2016 · 15 comments
Closed

ReferenceError: MouseEvent is not defined (Angular 2 Universal) #964

hongbo-miao opened this issue Sep 14, 2016 · 15 comments
Assignees

Comments

@hongbo-miao
Copy link
Contributor

hongbo-miao commented Sep 14, 2016

The old error is back when using latest universal-starter and ng2-bootstrap.

  • Angular 2 version rc6/rc7
  • ng2-bootstrap version 1.1.2
  • angular2-universal version 1.0.5

/my-project/node_modules/ng2-bootstrap/components/dropdown/dropdown-toggle.directive.js:62
__metadata('design:paramtypes', [MouseEvent]),
^

ReferenceError: MouseEvent is not defined
at /my-project/node_modules/ng2-bootstrap/components/dropdown/dropdown-toggle.directive.js:62:42
at Object. (/my-project/node_modules/ng2-bootstrap/components/dropdown/dropdown-toggle.directive.js:74:2)
at Module._compile (module.js:541:32)
at Object.Module._extensions..js (module.js:550:10)
at Module.load (module.js:458:32)
at tryModuleLoad (module.js:417:12)
at Function.Module._load (module.js:409:3)
at Module.require (module.js:468:17)
at require (internal/module.js:20:19)
at Object. (/my-project/node_modules/ng2-bootstrap/components/dropdown.js:4:35)
at Module._compile (module.js:541:32)
at Object.Module._extensions..js (module.js:550:10)
at Module.load (module.js:458:32)
at tryModuleLoad (module.js:417:12)
at Function.Module._load (module.js:409:3)
at Module.require (module.js:468:17)
at require (internal/module.js:20:19)
at Object. (/my-project/node_modules/ng2-bootstrap/ng2-bootstrap.js:12:10)
at Module._compile (module.js:541:32)
at Object.Module._extensions..js (module.js:550:10)
at Module.load (module.js:458:32)
at tryModuleLoad (module.js:417:12)

@hongbo-miao
Copy link
Contributor Author

hongbo-miao commented Sep 14, 2016

Just add

import { DropdownModule } from 'ng2-bootstrap/ng2-bootstrap';    // <- this line

 @NgModule({
    imports: [
      DropdownModule    // <- and this line
    ]
  })

in main.node.ts, you will see the error.

@Martin-Luft
Copy link
Contributor

@valorkin
Copy link
Member

It was more like a type hack for universal, maybe some typings could help or need to revert this hack back

@crebuh
Copy link

crebuh commented Sep 29, 2016

Any workaround in the meanwhile?

@u12206050
Copy link

u12206050 commented Sep 30, 2016

Only workaround I have found was to either use regexp-replace in webpack and search for [MouseEvent] and replace to [] and doing the same for KeyboardEvent etc. Do this only for the serverConfig in webpack.
{ test: /\.(ts|js)$/, loader: 'regexp-replace', query: { match: { pattern: '\\[(Mouse|Keyboard)Event\\]', flags: 'g' }, replaceWith: '[]', }, include: ['node_modules/ng2-bootstrap'] }

@crebuh
Copy link

crebuh commented Sep 30, 2016

@u12206050

thx for the tipp, I tried to remove it manually and it works. Just struggeling with the string-replace loader. I added the following code to my webpack config

  {
    test: /\.js$/,
    loader: 'string-replace',
    query: {
      multiple: [
        { search: '[MouseEvent]', replace: '[]', flags: 'g' },
        { search: '[KeyboardEvent]', replace: '[]', flags: 'g' }
      ]
    }
  }

But it doesn't work. Can you please provide your config? is there a possiblity to just scan the node_modules folders?

@valorkin valorkin self-assigned this Sep 30, 2016
@valorkin
Copy link
Member

Seems we have finished with AoT support, so I can revert a hack for universal

@Junik
Copy link

Junik commented Oct 3, 2016

work for me

{ test: /\.(ts|js)$/, loader: 'regexp-replace', query: { match: { pattern: '\\[(Mouse|Keyboard)Event\\]', flags: 'g' }, replaceWith: '[]', } }

@Martin-Luft
Copy link
Contributor

Is it working and we can close this issue?

@flashcrow2000
Copy link

@Junik It's been a long time, but maybe someone is still watching: where do you add the regex test? I'm using angular-cli v5

@u12206050
Copy link

@flashcrow2000 It is added into the webpack conf file. But this shouldn't be a problem anymore.

@flashcrow2000
Copy link

flashcrow2000 commented Nov 21, 2017

@u12206050 it is with another module.. google maps

@valorkin
Copy link
Member

@flashcrow2000 hope you are right, I hate as any so much, it kills an idea of typescript usage

@stephengardner
Copy link

This is still an issue. This is a recurring issue with events.

@valorkin
Copy link
Member

valorkin commented Mar 2, 2018

@stephengardner yep, this is why we are adding test of cypress + universal

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

8 participants