Does ES6 import/export need “.js” extension?

喜你入骨 提交于 2019-11-28 12:07:55

No, modules don't care about extensions. It just needs to be a name that resolves to a source file.

In your case, http://localhost/bla/src/drawImage is not a file while http://localhost/bla/src/drawImage.js is, so that's where there error comes from. You can configure your server to ignore the extension, for example. Webpack does the same.

The extension is part of the filename. You have to put it in.

As a proof try this:

  • rename file to drawImage.test
  • edit index.js to contain './drawImage.test'

Reload and you'll see the extendion js or test is completely arbirary, as long as you specify it in the export.

Obviously, after the test revert to the correct/better js extension.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!