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

[1.4.1] Uncaught TypeError: Cannot read property 'Move' of undefined #410

Closed
jason-yang opened this issue Aug 13, 2018 · 4 comments
Closed

Comments

@jason-yang
Copy link

jason-yang commented Aug 13, 2018

Likely duplicate of #308, but it was closed so I'm opening a new issue.

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[x] Bug report 
[ ] Feature request
[ ] Documentation issue or request

Current behavior

When using typescript to reference Cropper.DragMode.Move, compiler passes, but when loaded in browser we get the runtime error:

Uncaught TypeError: Cannot read property 'Move' of undefined

Expected behavior

For the enum to be usable in typescript and not throw a runtime error.

Minimal reproduction of the problem with instructions

  1. Using the code:
import Cropper from 'cropperjs';

const cropper = new Cropper(this.imageRef, {
    dragMode: Cropper.DragMode.Move,
    ...otherOptions
});
  1. Webpack and at-loader compiles the code fine.
  2. Load page on browser
  3. Got the following error:
Uncaught TypeError: Cannot read property 'Move' of undefined

What is the motivation / use case for changing the behavior?

Doing something like:

import Cropper from 'cropperjs';

const cropper = new Cropper(this.imageRef, {
    dragMode: 'move' as any,
    ...otherOptions
});

Defeats the purpose of strongly type code, and typings in general.

Environment


Cropper.js version: 1.4.1


Browser:
- [x] Chrome (desktop) version XX
- [ ] Chrome (Android) version XX
- [ ] Chrome (iOS) version XX
- [x] Firefox version XX
- [x] Safari (desktop) version XX
- [ ] Safari (iOS) version XX
- [ ] IE version XX
- [ ] Edge version XX

Others:

typescript version: 2.9.2
webpack version: 3.5.4


Relevant webpack config:

const config = {
  module: {
    rules: [
      {
        test: /\.jsx?$/,
        use: [{loader: 'babel-loader', options: {...stuff}],
        include: [
            ...otherIncludes,
            /cropperjs\/src/
        ]
      },
      {
        test: /\.tsx?$/,
        use: [{loader: 'awesome-typescript-loader', options: {...stuff}],
        include: [...otherIncludes, /cropperjs\/src/]
      }
    ]
  }
}
@fengyuanchen
Copy link
Owner

Cropper.DragMode is not existing.

@jason-yang
Copy link
Author

So... should it exist? Right now the declared enum is completely useless, and we might as well just use the string.

@fengyuanchen
Copy link
Owner

Because export enums in type defination file is not support in some TypeScript runtime.

@unrevised6419
Copy link

unrevised6419 commented Jan 18, 2019

{
  // ...
  dragMode: 'move' as Cropper.DragMode,
  // ...
}

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