繁体   English   中英

无法从支持的浏览器导入es6模块

[英]Unable to Import es6 modules from supported browser

尝试将moment.js导入为es6模块。 正在使用最新的Chrome版本。
根据此处的讨论,我尝试了src路径(es6)

import * as moment from './node_modules/moment/src/moment'

尽管跳过.js对于该线程上的每个人似乎都可以正常工作,但我无法使其正常工作。 但这有效

import * as moment from './node_modules/moment/src/moment.js'

然而,请求最终失败,因为导入一直试图在没有js扩展的情况下加载其依赖项

 GET http://127.0.0.1:8083/node_modules/moment/src/lib/utils/hooks net::ERR_ABORTED 404 (Not Found) moment.js:22
 GET http://127.0.0.1:8083/node_modules/moment/src/lib/moment/moment net::ERR_ABORTED 404 (Not Found) moment.js:26 
 GET http://127.0.0.1:8083/node_modules/moment/src/lib/moment/calendar net::ERR_ABORTED 404 (Not Found) moment.js:39 
 GET http://127.0.0.1:8083/node_modules/moment/src/lib/locale/locale net::ERR_ABORTED 404 (Not Found) moment.js:46 
 GET http://127.0.0.1:8083/node_modules/moment/src/lib/duration/duration net::ERR_ABORTED 404 (Not Found) moment.js:48 
 GET http://127.0.0.1:8083/node_modules/moment/src/lib/units/units net::ERR_ABORTED 404 (Not Found) moment.js:50 
 GET http://127.0.0.1:8083/node_modules/moment/src/lib/utils/is-date net::ERR_ABORTED 404 (Not Found) 

我所拥有的所有代码是带有此脚本标记的空白index.html

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

和一个main.js文件与此

import * as _ from './node_modules/underscore/underscore.js';
import * as moment from './node_modules/moment/src/moment.js';

Underscore.js导入并可以正常工作。 问题只是一时。 我究竟做错了什么? 还有为什么为什么在没有指定.js扩展名的情况下我无法加载这两个文件,而显然ithub线程上的文件却能够做到这一点

import * as moment from 'moment'

从ES6开始时,我也遇到类似的问题。 您可以尝试这种方式导入时刻

import moment from "moment";

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM