admin管理员组文章数量:1430143
In the latest chrome browser
import foo from '../dist/foo.mjs'
fails with
Failed to load module script: The server responded with a non-JavaScript MIME type of "". Strict MIME type checking is enforced for module scripts per HTML spec.
But if I copy the file to foo.js
import foo from '../dist/foo.js'
works!
I am using the mac os x built-in Apache server with localhost paths and the latest chrome.
So somehow es6 imports are sensitive, in the browser, to the preferred node suffix of .mjs.
The import is in a html file with <script type="module">
rather than a separate module file, but I doubt that is the problem.
Is there a solution to this?.
In the latest chrome browser
import foo from '../dist/foo.mjs'
fails with
Failed to load module script: The server responded with a non-JavaScript MIME type of "". Strict MIME type checking is enforced for module scripts per HTML spec.
But if I copy the file to foo.js
import foo from '../dist/foo.js'
works!
I am using the mac os x built-in Apache server with localhost paths and the latest chrome.
So somehow es6 imports are sensitive, in the browser, to the preferred node suffix of .mjs.
The import is in a html file with <script type="module">
rather than a separate module file, but I doubt that is the problem.
Is there a solution to this?.
Share Improve this question edited May 5, 2019 at 18:57 oguz ismail 51.1k16 gold badges60 silver badges79 bronze badges asked May 5, 2019 at 18:56 backspacesbackspaces 3,9627 gold badges38 silver badges62 bronze badges1 Answer
Reset to default 6You need to usa an .htaccess
file or extend your Apache config file with the following htaccess directive in order for the server to output files with the mjs extension with the correct MIME type:
<IfModule mod_mime.c>
AddType text/javascript js mjs
</IfModule>
Of course, mod_mime
needs to be installed and enabled for this to work.
本文标签: javascriptes6 import usingmjs suffix fails with MIME errorStack Overflow
版权声明:本文标题:javascript - es6 import using.mjs suffix fails with MIME error - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745534855a2662225.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论