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

[Vue] Error loading module #8

Closed
matiaslopezd opened this issue Mar 11, 2020 · 3 comments
Closed

[Vue] Error loading module #8

matiaslopezd opened this issue Mar 11, 2020 · 3 comments

Comments

@matiaslopezd
Copy link

matiaslopezd commented Mar 11, 2020

Hi again, I have a problem using in Vue.

Import

import ShortUniqueId from 'short-unique-id';
const uid = new ShortUniqueId();

Error

./node_modules/short-unique-id/src/index.js 12:10
Module parse failed: Unexpected token (12:10)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
| 
| class ShortUniqueId {
>   counter = 0;
| 
|   debug;
@matiaslopezd
Copy link
Author

matiaslopezd commented Mar 11, 2020

Temporaly solution to fix:

mounted() {
   const element = document.createElement('script');
   element.src = 'https://rawgit.com/jeanlescure/short-unique-id/master/dist/short-unique-id.min.js';
   element.setAttribute('async', 'true');
   document.body.appendChild(element);
}

And add in function on @click:

 const ShortUniqueId = window['short-unique-id'].default;
 const uid = new ShortUniqueId();
uid.randomUUID(10).toUpperCase();

@jeanlescure
Copy link
Collaborator

The package.json defines the module file as:

  "module": "src/index.js",

which means that any ES6 import will use the raw (pre-transpiled) js file.

I used class properties for development, as evidenced by my dev dependency:

@babel/plugin-proposal-class-properties

This is not a problem for projects that implement a plugin for transpiling class properties, but will cause the reported error otherwise.

The quickest workaround for versions < 2.0.5 is to add a plugin such as @babel/plugin-proposal-class-properties to the project.

For v2.0.6 I'll work on refactoring out the usage of class properties.

@jeanlescure
Copy link
Collaborator

@matiaslopezd version 2.0.6 is out now which should allow you to use the ES6 module import without error.

Cheers 🍾

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

2 participants