Js extension required for ES6 import / export?

I have installed Chrome beta - version 60.0.3112.24 (Official Build) beta (64-bit)

In chrome: // flags / I have enabled Experimental Web Platform features (see https://jakearchibald.com/2017/es-modules-in-browsers )

Then I tried:

<script type="module" src='bla/src/index.js'></script>

      

where index.js has the following line:

export { default as drawImage } from './drawImage';

      

This refers to the existing drawImage.js file

what I get in the console is an error in

GET http://localhost/bla/src/drawImage 

      

If I change the export and add the ".js" extension it works fine.

Is this a chrome bug or does ES6 require extension in this case?

Also webpack builds it without extension!

+3


source to share


2 answers


The extension is part of the file name. You have to put it down.

Try the following as evidence:

  • rename the file to drawImage.test

  • edit index.js

    contain'./drawImage.test'



Reload and you will see that the extension is js

or test

is fully arbirary if you specify it in export

.

Obviously go back to the correct / better extension after the test js

.

+3


source


No, modules don't care about extensions. It just has to be a name that resolves the original file.



In your case, http://localhost/bla/src/drawImage

it is not a file, but http://localhost/bla/src/drawImage.js

is where the error comes from. For example, you can configure the server to ignore the extension. Webpack does the same.

+2


source







All Articles