Error: Uncaught SyntaxError: Unexpected identifier

0

Hello, I am so new to this JavaScript , I hope someone can help me, I am trying to import some modules that will help me to compress images but I get an error:

  

Uncaught SyntaxError: Unexpected identifier

This is my code:

import axios from 'axios';
import ImageCompressor from 'image-compressor.js';

document.getElementById('files').addEventListener('change', (e) => {
  const file = e.target.files[0];

  if (!file) {
    return;
  }

  new ImageCompressor(file, {
    quality: .6,
    success(result) {
      const formData = new FormData();

      formData.append('files', result, result.name);

      // Send the compressed image file to server with XMLHttpRequest.
      axios.post('/path/to/upload', formData).then(() => {
        console.log('Upload success');
      });
    },
    error(e) {
      console.log(e.message);
    },
  });
});
<input type="file" id="files" name="image" multiple="true" accept=".png, .jpg, .jpeg"/>

This is the error that comes to me:

    
asked by Jose 24.05.2018 в 19:41
source

1 answer

0

I'm not sure what this is but try to put the path of the file:

import axios from './axios';
import ImageCompressor from './image-compressor';

You do not need to put the '.js' because the javascript module system already expects it to be a javascript file (it is taken for granted). Tell me if it works for you.

    
answered by 24.05.2018 в 20:14